Created
December 5, 2023 01:11
-
-
Save ku/535481ba42d9e1d63f7cd74d3816610a to your computer and use it in GitHub Desktop.
crypt/rand Int() distribution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"crypto/rand" | |
"math/big" | |
"os" | |
"github.com/aybabtme/uniplot/histogram" | |
) | |
func main() { | |
j := 1_000_000 | |
res := make([]float64, j) | |
for i := 0; i < j; i++ { | |
n, err := rand.Int(rand.Reader, big.NewInt(10_000)) | |
if err != nil { | |
panic(err.Error()) | |
} | |
res[i], _ = n.Float64() | |
} | |
hist := histogram.Hist(100, res) | |
err := histogram.Fprint(os.Stdout, hist, histogram.Linear(75)) | |
if err != nil { | |
panic(err.Error()) | |
} | |
} | |
/* | |
0-99.99 1% █████████████████████████████████████████████████████████████████████████▏ 9999 | |
99.99-200 1.01% █████████████████████████████████████████████████████████████████████████▋ 10061 | |
200-300 1.01% █████████████████████████████████████████████████████████████████████████▋ 10065 | |
300-400 0.998% ████████████████████████████████████████████████████████████████████████▉ 9976 | |
400-499.9 1% █████████████████████████████████████████████████████████████████████████▍ 10040 | |
499.9-599.9 1% █████████████████████████████████████████████████████████████████████████▍ 10036 | |
599.9-699.9 1.01% █████████████████████████████████████████████████████████████████████████▌ 10051 | |
699.9-799.9 0.991% ████████████████████████████████████████████████████████████████████████▍ 9906 | |
799.9-899.9 1.01% █████████████████████████████████████████████████████████████████████████▊ 10093 | |
899.9-999.9 0.999% █████████████████████████████████████████████████████████████████████████ 9989 | |
999.9-1100 1.02% ██████████████████████████████████████████████████████████████████████████▍ 10175 | |
1100-1200 0.995% ████████████████████████████████████████████████████████████████████████▋ 9945 | |
1200-1300 1.03% ███████████████████████████████████████████████████████████████████████████▏ 10266 | |
1300-1400 1.02% ██████████████████████████████████████████████████████████████████████████▊ 10238 | |
1400-1500 1.01% █████████████████████████████████████████████████████████████████████████▊ 10091 | |
1500-1600 1% █████████████████████████████████████████████████████████████████████████▏ 10001 | |
1600-1700 1% █████████████████████████████████████████████████████████████████████████▏ 10011 | |
1700-1800 0.985% ████████████████████████████████████████████████████████████████████████ 9850 | |
1800-1900 1% █████████████████████████████████████████████████████████████████████████▏ 10018 | |
1900-2000 0.999% █████████████████████████████████████████████████████████████████████████ 9991 | |
2000-2100 1% █████████████████████████████████████████████████████████████████████████▍ 10044 | |
2100-2200 0.987% ████████████████████████████████████████████████████████████████████████▏ 9873 | |
2200-2300 0.999% █████████████████████████████████████████████████████████████████████████ 9992 | |
2300-2400 0.993% ████████████████████████████████████████████████████████████████████████▋ 9934 | |
2400-2500 1% █████████████████████████████████████████████████████████████████████████▌ 10050 | |
2500-2600 1.01% ██████████████████████████████████████████████████████████████████████████ 10120 | |
2600-2700 1.01% █████████████████████████████████████████████████████████████████████████▋ 10076 | |
2700-2800 1.01% █████████████████████████████████████████████████████████████████████████▋ 10079 | |
2800-2900 0.986% ████████████████████████████████████████████████████████████████████████▏ 9859 | |
2900-3000 0.997% ████████████████████████████████████████████████████████████████████████▉ 9970 | |
3000-3100 0.979% ███████████████████████████████████████████████████████████████████████▋ 9788 | |
3100-3200 1% █████████████████████████████████████████████████████████████████████████▏ 10000 | |
3200-3300 0.994% ████████████████████████████████████████████████████████████████████████▋ 9940 | |
3300-3400 1.01% █████████████████████████████████████████████████████████████████████████▌ 10051 | |
3400-3500 1% █████████████████████████████████████████████████████████████████████████▏ 10015 | |
3500-3600 1.01% █████████████████████████████████████████████████████████████████████████▋ 10068 | |
3600-3700 0.982% ███████████████████████████████████████████████████████████████████████▊ 9822 | |
3700-3800 0.985% ████████████████████████████████████████████████████████████████████████ 9847 | |
3800-3900 0.989% ████████████████████████████████████████████████████████████████████████▎ 9894 | |
3900-4000 1.01% █████████████████████████████████████████████████████████████████████████▉ 10115 | |
4000-4100 1% █████████████████████████████████████████████████████████████████████████▏ 10008 | |
4100-4200 1% █████████████████████████████████████████████████████████████████████████▏ 9998 | |
4200-4300 0.996% ████████████████████████████████████████████████████████████████████████▊ 9961 | |
4300-4400 1% █████████████████████████████████████████████████████████████████████████▍ 10045 | |
4400-4500 0.993% ████████████████████████████████████████████████████████████████████████▋ 9933 | |
4500-4600 1.01% █████████████████████████████████████████████████████████████████████████▊ 10094 | |
4600-4700 0.988% ████████████████████████████████████████████████████████████████████████▎ 9884 | |
4700-4800 0.985% ████████████████████████████████████████████████████████████████████████ 9848 | |
4800-4900 0.989% ████████████████████████████████████████████████████████████████████████▎ 9888 | |
4900-5000 0.989% ████████████████████████████████████████████████████████████████████████▎ 9890 | |
5000-5099 1.01% █████████████████████████████████████████████████████████████████████████▋ 10086 | |
5099-5199 0.997% ████████████████████████████████████████████████████████████████████████▉ 9968 | |
5199-5299 1.01% █████████████████████████████████████████████████████████████████████████▊ 10094 | |
5299-5399 0.988% ████████████████████████████████████████████████████████████████████████▏ 9878 | |
5399-5499 0.976% ███████████████████████████████████████████████████████████████████████▍ 9762 | |
5499-5599 0.987% ████████████████████████████████████████████████████████████████████████▏ 9870 | |
5599-5699 1% █████████████████████████████████████████████████████████████████████████▍ 10038 | |
5699-5799 0.984% ███████████████████████████████████████████████████████████████████████▉ 9838 | |
5799-5899 0.987% ████████████████████████████████████████████████████████████████████████▏ 9865 | |
5899-5999 0.989% ████████████████████████████████████████████████████████████████████████▎ 9887 | |
5999-6099 1% █████████████████████████████████████████████████████████████████████████▏ 10011 | |
6099-6199 1.02% ██████████████████████████████████████████████████████████████████████████▎ 10166 | |
6199-6299 1.01% █████████████████████████████████████████████████████████████████████████▉ 10113 | |
6299-6399 1% █████████████████████████████████████████████████████████████████████████▎ 10021 | |
6399-6499 0.994% ████████████████████████████████████████████████████████████████████████▋ 9938 | |
6499-6599 1% █████████████████████████████████████████████████████████████████████████▏ 9999 | |
6599-6699 0.99% ████████████████████████████████████████████████████████████████████████▍ 9897 | |
6699-6799 1.01% █████████████████████████████████████████████████████████████████████████▌ 10060 | |
6799-6899 1.01% █████████████████████████████████████████████████████████████████████████▋ 10082 | |
6899-6999 1.01% █████████████████████████████████████████████████████████████████████████▌ 10055 | |
6999-7099 0.997% ████████████████████████████████████████████████████████████████████████▉ 9974 | |
7099-7199 1.01% █████████████████████████████████████████████████████████████████████████▌ 10058 | |
7199-7299 0.987% ████████████████████████████████████████████████████████████████████████▏ 9865 | |
7299-7399 1% █████████████████████████████████████████████████████████████████████████▍ 10046 | |
7399-7499 0.991% ████████████████████████████████████████████████████████████████████████▍ 9907 | |
7499-7599 0.993% ████████████████████████████████████████████████████████████████████████▋ 9930 | |
7599-7699 1% █████████████████████████████████████████████████████████████████████████▎ 10022 | |
7699-7799 1% █████████████████████████████████████████████████████████████████████████▏ 10017 | |
7799-7899 1.01% █████████████████████████████████████████████████████████████████████████▋ 10070 | |
7899-7999 1% █████████████████████████████████████████████████████████████████████████▏ 9995 | |
7999-8099 1.02% ██████████████████████████████████████████████████████████████████████████▌ 10191 | |
8099-8199 1.02% ██████████████████████████████████████████████████████████████████████████▎ 10164 | |
8199-8299 1.01% █████████████████████████████████████████████████████████████████████████▋ 10079 | |
8299-8399 1.01% █████████████████████████████████████████████████████████████████████████▋ 10078 | |
8399-8499 0.99% ████████████████████████████████████████████████████████████████████████▎ 9896 | |
8499-8599 1% █████████████████████████████████████████████████████████████████████████▍ 10038 | |
8599-8699 0.993% ████████████████████████████████████████████████████████████████████████▋ 9930 | |
8699-8799 0.995% ████████████████████████████████████████████████████████████████████████▊ 9954 | |
8799-8899 1% █████████████████████████████████████████████████████████████████████████▌ 10048 | |
8899-8999 1% █████████████████████████████████████████████████████████████████████████▏ 10011 | |
8999-9099 0.997% ████████████████████████████████████████████████████████████████████████▉ 9974 | |
9099-9199 1.01% █████████████████████████████████████████████████████████████████████████▋ 10081 | |
9199-9299 1.01% ██████████████████████████████████████████████████████████████████████████▏ 10140 | |
9299-9399 0.982% ███████████████████████████████████████████████████████████████████████▊ 9824 | |
9399-9499 0.994% ████████████████████████████████████████████████████████████████████████▋ 9939 | |
9499-9599 1% █████████████████████████████████████████████████████████████████████████▌ 10050 | |
9599-9699 1.01% █████████████████████████████████████████████████████████████████████████▊ 10093 | |
9699-9799 1% █████████████████████████████████████████████████████████████████████████▎ 10023 | |
9799-9899 1.02% ██████████████████████████████████████████████████████████████████████████▎ 10168 | |
9899-9999 0.992% ████████████████████████████████████████████████████████████████████████▌ 9919 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment