mathrand

package
Version: v0.0.0-...-aba1bef Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2019 License: LGPL-3.0 Imports: 2 Imported by: 0

README

GoDoc

A collection of popular fast PRNGs (non crypto). This implementations may be used as analog of math/rand.

Diehard tests result:

func passed weak failed score
Uint32AddIfShiftXOR 1 113 0.5
Uint32AddIfShiftXORWithReseed 9 4 101 11
Uint32AddRotate 1 1 112 1.5
Uint32AddRotateMultiply 9 1 104 9.5
Uint32AddRotateMultiplyWithReseed 24 17 73 32.5
Uint32AddRotateWithReseed 17 15 82 24.5
Uint32MultiplyAdd 7 3 104 8.5
Uint32MultiplyAddWithReseed 17 26 71 30
Uint32PCG 22 20 72 32
Uint32PCGWithReseed 18 22 74 29
Uint32Xorshift 24 12 78 30
Uint32XorshiftWithReseed 29 14 71 36
Uint64AddIfShiftXOR 3 111 1.5
Uint64AddIfShiftXORWithReseed 9 4 101 11
Uint64AddNRotateMultiply 17 21 76 27.5
Uint64AddNRotateMultiplyWithReseed 21 16 77 29
Uint64AddRotate 1 1 112 1.5
Uint64AddRotateMultiply 18 13 83 24.5
Uint64AddRotateMultiplyWithReseed 20 18 76 29
Uint64AddRotateWithReseed 24 8 82 28
Uint64MSWS 23 16 75 31
Uint64MSWSWithReseed 16 20 78 26
Uint64MultiplyAdd 11 11 92 16.5
Uint64MultiplyAddWithReseed 20 15 79 27.5
Uint64Xorshift 26 11 77 31.5
Uint64XorshiftWithReseed 19 16 79 27
Uint64Xoshiro256 36 10 68 41
Uint64Xoshiro256WithReseed 16 17 81 24.5
XORUint32AddIfShiftXOR 1 113 0.5
XORUint32AddIfShiftXORWithReseed 9 4 101 11
XORUint32AddRotate 1 1 112 1.5
XORUint32AddRotateMultiply 9 1 104 9.5
XORUint32AddRotateMultiplyWithReseed 24 17 73 32.5
XORUint32AddRotateWithReseed 17 15 82 24.5
XORUint32MultiplyAdd 8 2 104 9
XORUint32MultiplyAddWithReseed 17 26 71 30
XORUint32PCG 26 15 73 33.5
XORUint32PCGWithReseed 18 22 74 29
XORUint32Xorshift 25 11 78 30.5
XORUint32XorshiftWithReseed 29 14 71 36
XORUint64AddIfShiftXOR 3 111 1.5
XORUint64AddIfShiftXORWithReseed 9 4 101 11
XORUint64AddNRotateMultiply 17 21 76 27.5
XORUint64AddNRotateMultiplyWithReseed 21 16 77 29
XORUint64AddRotate 1 1 112 1.5
XORUint64AddRotateMultiply 19 10 85 24
XORUint64AddRotateMultiplyWithReseed 20 18 76 29
XORUint64AddRotateWithReseed 24 8 82 28
XORUint64MSWS 18 10 86 23
XORUint64MSWSWithReseed 16 20 78 26
XORUint64MultiplyAdd 11 11 92 16.5
XORUint64MultiplyAddWithReseed 20 15 79 27.5
XORUint64Xorshift 26 11 77 31.5
XORUint64XorshiftWithReseed 19 16 79 27
XORUint64Xoshiro256 20 19 75 29.5
XORUint64Xoshiro256WithReseed 16 17 81 24.5

If you need a fast PRNG then choose the fastest implementation which does not not fail on important-to-you tests.

Benchmarks:

BenchmarkReadUint64AddRotateMultiplyWithReseed65536Concurrent-12     	goos: linux
goarch: amd64
pkg: github.com/xaionaro-go/rand/mathrand
BenchmarkReadUint64AddRotateMultiply1-12                             	1000000000	         5.91 ns/op	 169.28 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64AddRotateMultiply16-12                            	1000000000	         5.94 ns/op	2692.28 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64AddRotateMultiply1024-12                          	83157897	       144 ns/op	7096.43 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64AddRotateMultiply65536-12                         	 1319334	      9101 ns/op	7201.32 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64AddRotateMultiply65536Concurrent-12               	 8676526	      1344 ns/op	48746.93 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64AddRotateMultiplyWithReseed1-12                   	1000000000	         5.67 ns/op	 176.32 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64AddRotateMultiplyWithReseed16-12                  	1000000000	         5.81 ns/op	2753.05 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64AddRotateMultiplyWithReseed1024-12                	78509712	       152 ns/op	6739.85 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64AddRotateMultiplyWithReseed65536-12               	 1236812	      9887 ns/op	6628.26 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64AddRotateMultiplyWithReseed65536Concurrent-12     	 5922577	      1973 ns/op	33218.97 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64AddNRotateMultiply1-12                            	1000000000	         7.69 ns/op	 130.08 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64AddNRotateMultiply16-12                           	1000000000	         8.79 ns/op	1819.23 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64AddNRotateMultiply1024-12                         	30040552	       393 ns/op	2602.58 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64AddNRotateMultiply65536-12                        	  478203	     24378 ns/op	2688.32 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64AddNRotateMultiply65536Concurrent-12              	 3086086	      3743 ns/op	17507.67 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64AddNRotateMultiplyWithReseed1-12                  	1000000000	         7.34 ns/op	 136.22 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64AddNRotateMultiplyWithReseed16-12                 	1000000000	         9.17 ns/op	1743.97 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64AddNRotateMultiplyWithReseed1024-12               	29574066	       406 ns/op	2519.95 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64AddNRotateMultiplyWithReseed65536-12              	  467214	     25746 ns/op	2545.47 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64AddNRotateMultiplyWithReseed65536Concurrent-12    	 2858484	      4047 ns/op	16193.68 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64MultiplyAdd1-12                                   	1000000000	         5.51 ns/op	 181.65 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64MultiplyAdd16-12                                  	1000000000	         5.37 ns/op	2979.11 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64MultiplyAdd1024-12                                	100000000	       114 ns/op	8963.90 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64MultiplyAdd65536-12                               	 1639879	      7346 ns/op	8921.67 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64MultiplyAdd65536Concurrent-12                     	 8702646	      1346 ns/op	48698.28 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64MultiplyAddWithReseed1-12                         	1000000000	         5.34 ns/op	 187.42 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64MultiplyAddWithReseed16-12                        	1000000000	         5.51 ns/op	2903.46 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64MultiplyAddWithReseed1024-12                      	96030442	       124 ns/op	8243.72 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64MultiplyAddWithReseed65536-12                     	 1509570	      7828 ns/op	8372.51 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64MultiplyAddWithReseed65536Concurrent-12           	 8741253	      1344 ns/op	48747.50 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64AddRotate1-12                                     	1000000000	         5.63 ns/op	 177.61 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64AddRotate16-12                                    	1000000000	         5.42 ns/op	2952.00 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64AddRotate1024-12                                  	182573494	        67.5 ns/op	15159.29 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64AddRotate65536-12                                 	 3237300	      3904 ns/op	16787.75 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64AddRotate65536Concurrent-12                       	12520366	       895 ns/op	73215.25 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64AddRotateWithReseed1-12                           	1000000000	         5.52 ns/op	 181.08 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64AddRotateWithReseed16-12                          	1000000000	         5.89 ns/op	2717.95 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64AddRotateWithReseed1024-12                        	100000000	       109 ns/op	9368.62 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64AddRotateWithReseed65536-12                       	 1971318	      5898 ns/op	11111.25 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64AddRotateWithReseed65536Concurrent-12             	 8502072	      1377 ns/op	47593.25 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64AddIfShiftXOR1-12                                 	1000000000	         6.84 ns/op	 146.21 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64AddIfShiftXOR16-12                                	1000000000	         5.75 ns/op	2783.81 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64AddIfShiftXOR1024-12                              	96096104	       118 ns/op	8650.74 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64AddIfShiftXOR65536-12                             	 1580743	      7537 ns/op	8694.85 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64AddIfShiftXOR65536Concurrent-12                   	 8580079	      1357 ns/op	48300.82 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64AddIfShiftXORWithReseed1-12                       	1000000000	         6.85 ns/op	 145.93 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64AddIfShiftXORWithReseed16-12                      	1000000000	         6.51 ns/op	2457.85 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64AddIfShiftXORWithReseed1024-12                    	93999710	       127 ns/op	8060.02 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64AddIfShiftXORWithReseed65536-12                   	 1491421	      7904 ns/op	8291.92 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64AddIfShiftXORWithReseed65536Concurrent-12         	 7076581	      1643 ns/op	39884.89 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64Xorshift1-12                                      	1000000000	         5.60 ns/op	 178.64 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64Xorshift16-12                                     	1000000000	         6.03 ns/op	2653.13 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64Xorshift1024-12                                   	65962977	       178 ns/op	5755.88 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64Xorshift65536-12                                  	 1000000	     11162 ns/op	5871.43 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64Xorshift65536Concurrent-12                        	 8347202	      1406 ns/op	46619.89 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64XorshiftWithReseed1-12                            	1000000000	         5.59 ns/op	 178.74 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64XorshiftWithReseed16-12                           	1000000000	         6.32 ns/op	2532.31 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64XorshiftWithReseed1024-12                         	64752655	       184 ns/op	5556.25 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64XorshiftWithReseed65536-12                        	 1000000	     11752 ns/op	5576.69 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64XorshiftWithReseed65536Concurrent-12              	 6884772	      1707 ns/op	38402.60 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64Xoshiro2561-12                                    	1000000000	         8.77 ns/op	 113.99 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64Xoshiro25616-12                                   	1000000000	         7.19 ns/op	2225.54 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64Xoshiro2561024-12                                 	86924043	       135 ns/op	7585.89 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64Xoshiro25665536-12                                	 1419520	      8245 ns/op	7948.93 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64Xoshiro25665536Concurrent-12                      	 5786520	      2001 ns/op	32754.42 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64Xoshiro256WithReseed1-12                          	1000000000	         9.06 ns/op	 110.36 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64Xoshiro256WithReseed16-12                         	1000000000	         7.57 ns/op	2114.84 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64Xoshiro256WithReseed1024-12                       	74240482	       162 ns/op	6338.42 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64Xoshiro256WithReseed65536-12                      	 1242190	      9781 ns/op	6700.03 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64Xoshiro256WithReseed65536Concurrent-12            	 4955490	      2349 ns/op	27900.09 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64MSWS1-12                                          	1000000000	         6.16 ns/op	 162.27 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64MSWS16-12                                         	1000000000	         5.74 ns/op	2785.31 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64MSWS1024-12                                       	68370486	       175 ns/op	5846.41 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64MSWS65536-12                                      	 1000000	     11141 ns/op	5882.29 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64MSWS65536Concurrent-12                            	 8380882	      1411 ns/op	46448.32 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64MSWSWithReseed1-12                                	1000000000	         5.94 ns/op	 168.49 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64MSWSWithReseed16-12                               	1000000000	         5.92 ns/op	2702.21 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64MSWSWithReseed1024-12                             	63563898	       179 ns/op	5709.31 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64MSWSWithReseed65536-12                            	 1000000	     11522 ns/op	5688.06 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint64MSWSWithReseed65536Concurrent-12                  	 7868062	      1495 ns/op	43825.05 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32AddRotateMultiply1-12                             	1000000000	         5.32 ns/op	 187.81 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32AddRotateMultiply16-12                            	1000000000	         5.81 ns/op	2752.89 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32AddRotateMultiply1024-12                          	50419069	       232 ns/op	4406.42 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32AddRotateMultiply65536-12                         	  803712	     14584 ns/op	4493.60 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32AddRotateMultiply65536Concurrent-12               	 6675978	      1776 ns/op	36909.88 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32AddRotateMultiplyWithReseed1-12                   	1000000000	         5.38 ns/op	 185.81 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32AddRotateMultiplyWithReseed16-12                  	1000000000	         6.22 ns/op	2570.96 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32AddRotateMultiplyWithReseed1024-12                	50033872	       240 ns/op	4266.25 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32AddRotateMultiplyWithReseed65536-12               	  769466	     15656 ns/op	4185.96 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32AddRotateMultiplyWithReseed65536Concurrent-12     	 6265228	      1862 ns/op	35190.64 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32MultiplyAdd1-12                                   	1000000000	         5.12 ns/op	 195.33 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32MultiplyAdd16-12                                  	1000000000	         6.20 ns/op	2580.01 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32MultiplyAdd1024-12                                	51695251	       230 ns/op	4459.82 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32MultiplyAdd65536-12                               	  809083	     14668 ns/op	4468.03 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32MultiplyAdd65536Concurrent-12                     	 6688881	      1745 ns/op	37553.21 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32MultiplyAddWithReseed1-12                         	1000000000	         5.19 ns/op	 192.58 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32MultiplyAddWithReseed16-12                        	1000000000	         6.51 ns/op	2457.16 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32MultiplyAddWithReseed1024-12                      	49158019	       240 ns/op	4275.36 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32MultiplyAddWithReseed65536-12                     	  784038	     14898 ns/op	4398.93 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32MultiplyAddWithReseed65536Concurrent-12           	 6654824	      1775 ns/op	36927.91 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32AddRotate1-12                                     	1000000000	         5.58 ns/op	 179.24 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32AddRotate16-12                                    	1000000000	         6.17 ns/op	2591.94 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32AddRotate1024-12                                  	146871367	        82.6 ns/op	12395.59 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32AddRotate65536-12                                 	 2419917	      4974 ns/op	13176.65 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32AddRotate65536Concurrent-12                       	10127445	      1147 ns/op	57153.43 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32AddRotateWithReseed1-12                           	1000000000	         5.31 ns/op	 188.28 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32AddRotateWithReseed16-12                          	1000000000	         6.22 ns/op	2573.78 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32AddRotateWithReseed1024-12                        	100000000	       118 ns/op	8674.39 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32AddRotateWithReseed65536-12                       	 1759989	      6783 ns/op	9662.51 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32AddRotateWithReseed65536Concurrent-12             	 6268934	      1703 ns/op	38474.10 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32AddIfShiftXOR1-12                                 	1000000000	         6.77 ns/op	 147.70 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32AddIfShiftXOR16-12                                	1000000000	         6.78 ns/op	2359.86 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32AddIfShiftXOR1024-12                              	51157076	       234 ns/op	4378.01 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32AddIfShiftXOR65536-12                             	  799681	     14744 ns/op	4444.93 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32AddIfShiftXOR65536Concurrent-12                   	 4693885	      2540 ns/op	25799.37 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32AddIfShiftXORWithReseed1-12                       	1000000000	         6.78 ns/op	 147.50 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32AddIfShiftXORWithReseed16-12                      	1000000000	         7.80 ns/op	2050.32 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32AddIfShiftXORWithReseed1024-12                    	47704569	       247 ns/op	4153.08 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32AddIfShiftXORWithReseed65536-12                   	  771753	     15423 ns/op	4249.19 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32AddIfShiftXORWithReseed65536Concurrent-12         	 3737464	      3095 ns/op	21173.48 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32Xorshift1-12                                      	1000000000	         5.57 ns/op	 179.44 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32Xorshift16-12                                     	1000000000	         7.44 ns/op	2150.19 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32Xorshift1024-12                                   	33225739	       352 ns/op	2910.57 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32Xorshift65536-12                                  	  537823	     22274 ns/op	2942.30 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32Xorshift65536Concurrent-12                        	 4218126	      2778 ns/op	23588.19 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32XorshiftWithReseed1-12                            	1000000000	         5.29 ns/op	 188.91 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32XorshiftWithReseed16-12                           	1000000000	         7.89 ns/op	2028.97 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32XorshiftWithReseed1024-12                         	32440348	       368 ns/op	2781.00 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32XorshiftWithReseed65536-12                        	  518901	     23133 ns/op	2833.01 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32XorshiftWithReseed65536Concurrent-12              	 3472923	      3502 ns/op	18713.59 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32PCG1-12                                           	1000000000	         6.85 ns/op	 145.96 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32PCG16-12                                          	941233701	        13.3 ns/op	1204.04 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32PCG1024-12                                        	25314841	       479 ns/op	2139.24 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32PCG65536-12                                       	  403969	     30289 ns/op	2163.68 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32PCG65536Concurrent-12                             	 1735347	      6712 ns/op	9764.48 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32PCGWithReseed1-12                                 	1000000000	         6.68 ns/op	 149.59 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32PCGWithReseed16-12                                	877823248	        13.4 ns/op	1193.18 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32PCGWithReseed1024-12                              	22678197	       551 ns/op	1860.05 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32PCGWithReseed65536-12                             	  357106	     34185 ns/op	1917.10 MB/s	       0 B/op	       0 allocs/op
BenchmarkReadUint32PCGWithReseed65536Concurrent-12                   	 1471394	      7832 ns/op	8367.92 MB/s	       0 B/op	       0 allocs/op
BenchmarkStandardRead1-12                                            	620167975	        19.0 ns/op	  52.51 MB/s	       0 B/op	       0 allocs/op
BenchmarkStandardRead16-12                                           	377367787	        30.9 ns/op	 517.92 MB/s	       0 B/op	       0 allocs/op
BenchmarkStandardRead1024-12                                         	11654818	      1034 ns/op	 990.69 MB/s	       0 B/op	       0 allocs/op
BenchmarkStandardRead65536-12                                        	  183195	     65467 ns/op	1001.06 MB/s	       0 B/op	       0 allocs/op
BenchmarkStandardRead16777216-12                                     	     698	  16642155 ns/op	1008.12 MB/s	       0 B/op	       0 allocs/op
BenchmarkLukechampine1-12                                            	461865512	        23.5 ns/op	  42.61 MB/s	       0 B/op	       0 allocs/op
BenchmarkLukechampine1024-12                                         	36983640	       322 ns/op	3184.26 MB/s	       0 B/op	       0 allocs/op
BenchmarkLukechampine65536-12                                        	  933505	     12436 ns/op	5269.75 MB/s	       0 B/op	       0 allocs/op
BenchmarkLukechampine16777216-12                                     	    3508	   3393452 ns/op	4944.00 MB/s	       0 B/op	       0 allocs/op
BenchmarkUint32AddRotateMultiply-12                                  	1000000000	         1.76 ns/op	2267.26 MB/s	       0 B/op	       0 allocs/op
BenchmarkUint32MultiplyAdd-12                                        	1000000000	         1.86 ns/op	2150.87 MB/s	       0 B/op	       0 allocs/op
BenchmarkUint32AddRotate-12                                          	1000000000	         1.60 ns/op	2500.27 MB/s	       0 B/op	       0 allocs/op
BenchmarkUint32AddIfShiftXOR-12                                      	1000000000	         2.29 ns/op	1747.12 MB/s	       0 B/op	       0 allocs/op
BenchmarkUint32Xorshift-12                                           	1000000000	         2.05 ns/op	1950.09 MB/s	       0 B/op	       0 allocs/op
BenchmarkUint32PCG-12                                                	1000000000	         1.61 ns/op	2491.62 MB/s	       0 B/op	       0 allocs/op
BenchmarkUint64AddRotateMultiply-12                                  	1000000000	         1.95 ns/op	4105.49 MB/s	       0 B/op	       0 allocs/op
BenchmarkUint64AddNRotateMultiply-12                                 	1000000000	         3.70 ns/op	2163.08 MB/s	       0 B/op	       0 allocs/op
BenchmarkUint64MultiplyAdd-12                                        	1000000000	         1.87 ns/op	4267.77 MB/s	       0 B/op	       0 allocs/op
BenchmarkUint64AddRotate-12                                          	1000000000	         1.57 ns/op	5110.60 MB/s	       0 B/op	       0 allocs/op
BenchmarkUint64AddIfShiftXOR-12                                      	1000000000	         2.07 ns/op	3856.38 MB/s	       0 B/op	       0 allocs/op
BenchmarkUint64Xorshift-12                                           	1000000000	         2.11 ns/op	3783.07 MB/s	       0 B/op	       0 allocs/op
BenchmarkUint64Xoshiro256-12                                         	1000000000	         3.41 ns/op	2342.74 MB/s	       0 B/op	       0 allocs/op
BenchmarkUint64MSWS-12                                               	1000000000	         2.08 ns/op	3850.44 MB/s	       0 B/op	       0 allocs/op
BenchmarkStandardIntn-12                                             	688455276	        16.7 ns/op	 479.42 MB/s	       0 B/op	       0 allocs/op
BenchmarkValyalaUint32n-12                                           	755310522	        16.2 ns/op	 247.60 MB/s	       0 B/op	       0 allocs/op
BenchmarkValyalaUint32n_withPreparedRNG-12                           	1000000000	         2.23 ns/op	1793.55 MB/s	       0 B/op	       0 allocs/op
BenchmarkNebulousLabsIntn-12                                         	79827997	       150 ns/op	  53.42 MB/s	       0 B/op	       0 allocs/op
BenchmarkLukechampineUint64n-12                                      	319181235	        36.5 ns/op	 218.92 MB/s	       0 B/op	       0 allocs/op
BenchmarkTimeNowUnixNano-12                                          	336841614	        35.6 ns/op	 224.61 MB/s	       0 B/op	       0 allocs/op
PASS
ok  	github.com/xaionaro-go/rand/mathrand	1801.846s

Other fast PRNGs implementations:

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// GlobalPRNG is just an initialized (ready-to-use) PRNG which could
	// be used from anywhere.
	GlobalPRNG = New()
)

Functions

func ReduceUint32

func ReduceUint32(src, mod uint32) uint32

ReduceUint32 returns `src` as a value smaller than `mod`.

Based on: http://lemire.me/blog/2016/06/27/a-fast-alternative-to-the-modulo-reduction/

For fair distribution of results `src` shouldn't be reduced, it should be an uint32 mathrandom number [0..2^32).

func ReduceUint64

func ReduceUint64(src, mod uint64) uint64

ReduceUint64 returns `src` as a value smaller than `mod`.

Types

type PRNG

type PRNG struct {
	// contains filtered or unexported fields
}

PRNG is a instance of a pseudo-mathrandom number generator.

func New

func New() *PRNG

New creates new instance of pseudo-mathrandom number generator.

Methods of PRNG are not thread-safe in formal terms (which is usually not important for an PRNG) and it sometimes may return the same value to concurrent routines. If you need a non-copy guarantee among concurrent calls of a method (for example for "nonce") then you can use different instances of mathrand.PRNG for different goroutines. Also if you use a random number for example for sampling then you can safely use this function (because such errors won't make any negative effect to your application).

And example for multiple goroutines:

	var prngPool = sync.Pool{New: func() interface{}{ return mathrand.New() }}
	...
	prng := prngPool.Get().(*mathrand.PRNG).
	prng.ReadUint64Xoshiro256(b)
 prngPoo.Put(prng)

Note: Random numbers of this PRNG could easily be predicted (it's not an analog of crypto/rand).

func NewWithSeed

func NewWithSeed(seed uint64) *PRNG

NewWithSeed is the same as `New` but initializes the PRNG with predefined seed.

func (*PRNG) ReadUint32AddIfShiftXOR

func (prng *PRNG) ReadUint32AddIfShiftXOR(b []byte) (l int, err error)

ReadUint32AddIfShiftXOR is an analog of math/rand.Read. This random numbers could easily be predicted (it's not an analog of crypto/rand.Read).

Applied PRNG method: Uint32AddIfShiftXOR is a very fast (but weak) analog of `math/rand.Uint32`.

func (*PRNG) ReadUint32AddIfShiftXORWithReseed

func (prng *PRNG) ReadUint32AddIfShiftXORWithReseed(b []byte) (l int, err error)

ReadUint32AddIfShiftXORWithReseed is an analog of math/rand.Read. This random numbers could easily be predicted (it's not an analog of crypto/rand.Read).

"Reseed" forces to use a new seed (generated using XORShift method) on setting value to a pointer `& 0xff < 4`. Sometimes it allows to improve randomness of random numbers with a small performance impact. This method makes sense only if len(b) is large enough (>= 256 bytes). Otherwise it could affect strongly performance or it will not improve the randomness.

Applied PRNG method: Uint32AddIfShiftXOR is a very fast (but weak) analog of `math/rand.Uint32`.

func (*PRNG) ReadUint32AddRotate

func (prng *PRNG) ReadUint32AddRotate(b []byte) (l int, err error)

ReadUint32AddRotate is an analog of math/rand.Read. This random numbers could easily be predicted (it's not an analog of crypto/rand.Read).

Applied PRNG method: Uint32AddRotate is a very fast (but weak) analog of `math/rand.Uint32`.

func (*PRNG) ReadUint32AddRotateMultiply

func (prng *PRNG) ReadUint32AddRotateMultiply(b []byte) (l int, err error)

ReadUint32AddRotateMultiply is an analog of math/rand.Read. This random numbers could easily be predicted (it's not an analog of crypto/rand.Read).

Applied PRNG method: Uint32AddRotateMultiply is a fast analog of `math/rand.Uint32`.

The reliability on statistical tests of this method is unknown. This is improved LCG method, so see also Uint32MultiplyAdd.

func (*PRNG) ReadUint32AddRotateMultiplyWithReseed

func (prng *PRNG) ReadUint32AddRotateMultiplyWithReseed(b []byte) (l int, err error)

ReadUint32AddRotateMultiplyWithReseed is an analog of math/rand.Read. This random numbers could easily be predicted (it's not an analog of crypto/rand.Read).

"Reseed" forces to use a new seed (generated using XORShift method) on setting value to a pointer `& 0xff < 4`. Sometimes it allows to improve randomness of random numbers with a small performance impact. This method makes sense only if len(b) is large enough (>= 256 bytes). Otherwise it could affect strongly performance or it will not improve the randomness.

Applied PRNG method: Uint32AddRotateMultiply is a fast analog of `math/rand.Uint32`.

The reliability on statistical tests of this method is unknown. This is improved LCG method, so see also Uint32MultiplyAdd.

func (*PRNG) ReadUint32AddRotateWithReseed

func (prng *PRNG) ReadUint32AddRotateWithReseed(b []byte) (l int, err error)

ReadUint32AddRotateWithReseed is an analog of math/rand.Read. This random numbers could easily be predicted (it's not an analog of crypto/rand.Read).

"Reseed" forces to use a new seed (generated using XORShift method) on setting value to a pointer `& 0xff < 4`. Sometimes it allows to improve randomness of random numbers with a small performance impact. This method makes sense only if len(b) is large enough (>= 256 bytes). Otherwise it could affect strongly performance or it will not improve the randomness.

Applied PRNG method: Uint32AddRotate is a very fast (but weak) analog of `math/rand.Uint32`.

func (*PRNG) ReadUint32MultiplyAdd

func (prng *PRNG) ReadUint32MultiplyAdd(b []byte) (l int, err error)

ReadUint32MultiplyAdd is an analog of math/rand.Read. This random numbers could easily be predicted (it's not an analog of crypto/rand.Read).

Applied PRNG method: Uint32MultiplyAdd is a fast (but week) analog of `math/rand.Uint32`.

See also: https://en.wikipedia.org/wiki/Linear_congruential_generator

func (*PRNG) ReadUint32MultiplyAddWithReseed

func (prng *PRNG) ReadUint32MultiplyAddWithReseed(b []byte) (l int, err error)

ReadUint32MultiplyAddWithReseed is an analog of math/rand.Read. This random numbers could easily be predicted (it's not an analog of crypto/rand.Read).

"Reseed" forces to use a new seed (generated using XORShift method) on setting value to a pointer `& 0xff < 4`. Sometimes it allows to improve randomness of random numbers with a small performance impact. This method makes sense only if len(b) is large enough (>= 256 bytes). Otherwise it could affect strongly performance or it will not improve the randomness.

Applied PRNG method: Uint32MultiplyAdd is a fast (but week) analog of `math/rand.Uint32`.

See also: https://en.wikipedia.org/wiki/Linear_congruential_generator

func (*PRNG) ReadUint32PCG

func (prng *PRNG) ReadUint32PCG(b []byte) (l int, err error)

ReadUint32PCG is an analog of math/rand.Read. This random numbers could easily be predicted (it's not an analog of crypto/rand.Read).

Applied PRNG method: See also: https://en.wikipedia.org/wiki/Permuted_congruential_generator

func (*PRNG) ReadUint32PCGWithReseed

func (prng *PRNG) ReadUint32PCGWithReseed(b []byte) (l int, err error)

ReadUint32PCGWithReseed is an analog of math/rand.Read. This random numbers could easily be predicted (it's not an analog of crypto/rand.Read).

"Reseed" forces to use a new seed (generated using XORShift method) on setting value to a pointer `& 0xff < 4`. Sometimes it allows to improve randomness of random numbers with a small performance impact. This method makes sense only if len(b) is large enough (>= 256 bytes). Otherwise it could affect strongly performance or it will not improve the randomness.

Applied PRNG method: See also: https://en.wikipedia.org/wiki/Permuted_congruential_generator

func (*PRNG) ReadUint32Xorshift

func (prng *PRNG) ReadUint32Xorshift(b []byte) (l int, err error)

ReadUint32Xorshift is an analog of math/rand.Read. This random numbers could easily be predicted (it's not an analog of crypto/rand.Read).

Applied PRNG method: Uint32Xorshift is a very fast (but weak) analog of `math/rand.Uint32`.

See also: https://en.wikipedia.org/wiki/Xorshift

func (*PRNG) ReadUint32XorshiftWithReseed

func (prng *PRNG) ReadUint32XorshiftWithReseed(b []byte) (l int, err error)

ReadUint32XorshiftWithReseed is an analog of math/rand.Read. This random numbers could easily be predicted (it's not an analog of crypto/rand.Read).

"Reseed" forces to use a new seed (generated using XORShift method) on setting value to a pointer `& 0xff < 4`. Sometimes it allows to improve randomness of random numbers with a small performance impact. This method makes sense only if len(b) is large enough (>= 256 bytes). Otherwise it could affect strongly performance or it will not improve the randomness.

Applied PRNG method: Uint32Xorshift is a very fast (but weak) analog of `math/rand.Uint32`.

See also: https://en.wikipedia.org/wiki/Xorshift

func (*PRNG) ReadUint64AddIfShiftXOR

func (prng *PRNG) ReadUint64AddIfShiftXOR(b []byte) (l int, err error)

ReadUint64AddIfShiftXOR is an analog of math/rand.Read. This random numbers could easily be predicted (it's not an analog of crypto/rand.Read).

Applied PRNG method: Uint64AddIfShiftXOR is a very fast (but weak) analog of `math/rand.Uint32`.

func (*PRNG) ReadUint64AddIfShiftXORWithReseed

func (prng *PRNG) ReadUint64AddIfShiftXORWithReseed(b []byte) (l int, err error)

ReadUint64AddIfShiftXORWithReseed is an analog of math/rand.Read. This random numbers could easily be predicted (it's not an analog of crypto/rand.Read).

"Reseed" forces to use a new seed (generated using XORShift method) on setting value to a pointer `& 0xff < 8`. Sometimes it allows to improve randomness of random numbers with a small performance impact. This method makes sense only if len(b) is large enough (>= 256 bytes). Otherwise it could affect strongly performance or it will not improve the randomness.

Applied PRNG method: Uint64AddIfShiftXOR is a very fast (but weak) analog of `math/rand.Uint32`.

func (*PRNG) ReadUint64AddNRotateMultiply

func (prng *PRNG) ReadUint64AddNRotateMultiply(b []byte) (l int, err error)

ReadUint64AddNRotateMultiply is an analog of math/rand.Read. This random numbers could easily be predicted (it's not an analog of crypto/rand.Read).

Applied PRNG method: Uint64AddNRotateMultiply is a fast analog of `math/rand.Uint64`.

The reliability on statistical tests of this method is unknown. This is improved LCG method, so see also Uint64MultiplyAdd.

func (*PRNG) ReadUint64AddNRotateMultiplyWithReseed

func (prng *PRNG) ReadUint64AddNRotateMultiplyWithReseed(b []byte) (l int, err error)

ReadUint64AddNRotateMultiplyWithReseed is an analog of math/rand.Read. This random numbers could easily be predicted (it's not an analog of crypto/rand.Read).

"Reseed" forces to use a new seed (generated using XORShift method) on setting value to a pointer `& 0xff < 8`. Sometimes it allows to improve randomness of random numbers with a small performance impact. This method makes sense only if len(b) is large enough (>= 256 bytes). Otherwise it could affect strongly performance or it will not improve the randomness.

Applied PRNG method: Uint64AddNRotateMultiply is a fast analog of `math/rand.Uint64`.

The reliability on statistical tests of this method is unknown. This is improved LCG method, so see also Uint64MultiplyAdd.

func (*PRNG) ReadUint64AddRotate

func (prng *PRNG) ReadUint64AddRotate(b []byte) (l int, err error)

ReadUint64AddRotate is an analog of math/rand.Read. This random numbers could easily be predicted (it's not an analog of crypto/rand.Read).

Applied PRNG method: Uint64AddRotate is a very fast (but weak) analog of `math/rand.Uint64`.

func (*PRNG) ReadUint64AddRotateMultiply

func (prng *PRNG) ReadUint64AddRotateMultiply(b []byte) (l int, err error)

ReadUint64AddRotateMultiply is an analog of math/rand.Read. This random numbers could easily be predicted (it's not an analog of crypto/rand.Read).

Applied PRNG method: Uint64AddRotateMultiply is a fast analog of `math/rand.Uint64`.

The reliability on statistical tests of this method is unknown. This is improved LCG method, so see also Uint64MultiplyAdd.

func (*PRNG) ReadUint64AddRotateMultiplyWithReseed

func (prng *PRNG) ReadUint64AddRotateMultiplyWithReseed(b []byte) (l int, err error)

ReadUint64AddRotateMultiplyWithReseed is an analog of math/rand.Read. This random numbers could easily be predicted (it's not an analog of crypto/rand.Read).

"Reseed" forces to use a new seed (generated using XORShift method) on setting value to a pointer `& 0xff < 8`. Sometimes it allows to improve randomness of random numbers with a small performance impact. This method makes sense only if len(b) is large enough (>= 256 bytes). Otherwise it could affect strongly performance or it will not improve the randomness.

Applied PRNG method: Uint64AddRotateMultiply is a fast analog of `math/rand.Uint64`.

The reliability on statistical tests of this method is unknown. This is improved LCG method, so see also Uint64MultiplyAdd.

func (*PRNG) ReadUint64AddRotateWithReseed

func (prng *PRNG) ReadUint64AddRotateWithReseed(b []byte) (l int, err error)

ReadUint64AddRotateWithReseed is an analog of math/rand.Read. This random numbers could easily be predicted (it's not an analog of crypto/rand.Read).

"Reseed" forces to use a new seed (generated using XORShift method) on setting value to a pointer `& 0xff < 8`. Sometimes it allows to improve randomness of random numbers with a small performance impact. This method makes sense only if len(b) is large enough (>= 256 bytes). Otherwise it could affect strongly performance or it will not improve the randomness.

Applied PRNG method: Uint64AddRotate is a very fast (but weak) analog of `math/rand.Uint64`.

func (*PRNG) ReadUint64MSWS

func (prng *PRNG) ReadUint64MSWS(b []byte) (l int, err error)

ReadUint64MSWS is an analog of math/rand.Read. This random numbers could easily be predicted (it's not an analog of crypto/rand.Read).

Applied PRNG method: See also: https://en.wikipedia.org/wiki/Middle-square_method

func (*PRNG) ReadUint64MSWSWithReseed

func (prng *PRNG) ReadUint64MSWSWithReseed(b []byte) (l int, err error)

ReadUint64MSWSWithReseed is an analog of math/rand.Read. This random numbers could easily be predicted (it's not an analog of crypto/rand.Read).

"Reseed" forces to use a new seed (generated using XORShift method) on setting value to a pointer `& 0xff < 8`. Sometimes it allows to improve randomness of random numbers with a small performance impact. This method makes sense only if len(b) is large enough (>= 256 bytes). Otherwise it could affect strongly performance or it will not improve the randomness.

Applied PRNG method: See also: https://en.wikipedia.org/wiki/Middle-square_method

func (*PRNG) ReadUint64MultiplyAdd

func (prng *PRNG) ReadUint64MultiplyAdd(b []byte) (l int, err error)

ReadUint64MultiplyAdd is an analog of math/rand.Read. This random numbers could easily be predicted (it's not an analog of crypto/rand.Read).

Applied PRNG method: Uint64MultiplyAdd is a fast (but week) analog of `math/rand.Uint64`.

See also: https://en.wikipedia.org/wiki/Linear_congruential_generator

func (*PRNG) ReadUint64MultiplyAddWithReseed

func (prng *PRNG) ReadUint64MultiplyAddWithReseed(b []byte) (l int, err error)

ReadUint64MultiplyAddWithReseed is an analog of math/rand.Read. This random numbers could easily be predicted (it's not an analog of crypto/rand.Read).

"Reseed" forces to use a new seed (generated using XORShift method) on setting value to a pointer `& 0xff < 8`. Sometimes it allows to improve randomness of random numbers with a small performance impact. This method makes sense only if len(b) is large enough (>= 256 bytes). Otherwise it could affect strongly performance or it will not improve the randomness.

Applied PRNG method: Uint64MultiplyAdd is a fast (but week) analog of `math/rand.Uint64`.

See also: https://en.wikipedia.org/wiki/Linear_congruential_generator

func (*PRNG) ReadUint64Xorshift

func (prng *PRNG) ReadUint64Xorshift(b []byte) (l int, err error)

ReadUint64Xorshift is an analog of math/rand.Read. This random numbers could easily be predicted (it's not an analog of crypto/rand.Read).

Applied PRNG method: Uint64Xorshift is a very fast (but weak) analog of `math/rand.Uint64`.

See also: https://en.wikipedia.org/wiki/Xorshift

func (*PRNG) ReadUint64XorshiftWithReseed

func (prng *PRNG) ReadUint64XorshiftWithReseed(b []byte) (l int, err error)

ReadUint64XorshiftWithReseed is an analog of math/rand.Read. This random numbers could easily be predicted (it's not an analog of crypto/rand.Read).

"Reseed" forces to use a new seed (generated using XORShift method) on setting value to a pointer `& 0xff < 8`. Sometimes it allows to improve randomness of random numbers with a small performance impact. This method makes sense only if len(b) is large enough (>= 256 bytes). Otherwise it could affect strongly performance or it will not improve the randomness.

Applied PRNG method: Uint64Xorshift is a very fast (but weak) analog of `math/rand.Uint64`.

See also: https://en.wikipedia.org/wiki/Xorshift

func (*PRNG) ReadUint64Xoshiro256

func (prng *PRNG) ReadUint64Xoshiro256(b []byte) (l int, err error)

ReadUint64Xoshiro256 is an analog of math/rand.Read. This random numbers could easily be predicted (it's not an analog of crypto/rand.Read).

Applied PRNG method: See also: https://en.wikipedia.org/wiki/Xorshift#xoshiro_and_xoroshiro

func (*PRNG) ReadUint64Xoshiro256WithReseed

func (prng *PRNG) ReadUint64Xoshiro256WithReseed(b []byte) (l int, err error)

ReadUint64Xoshiro256WithReseed is an analog of math/rand.Read. This random numbers could easily be predicted (it's not an analog of crypto/rand.Read).

"Reseed" forces to use a new seed (generated using XORShift method) on setting value to a pointer `& 0xff < 8`. Sometimes it allows to improve randomness of random numbers with a small performance impact. This method makes sense only if len(b) is large enough (>= 256 bytes). Otherwise it could affect strongly performance or it will not improve the randomness.

Applied PRNG method: See also: https://en.wikipedia.org/wiki/Xorshift#xoshiro_and_xoroshiro

func (*PRNG) Reseed

func (prng *PRNG) Reseed()

func (*PRNG) SetSeed

func (prng *PRNG) SetSeed(seed uint64)

func (*PRNG) Uint32AddIfShiftXOR

func (prng *PRNG) Uint32AddIfShiftXOR() uint32

Uint32AddIfShiftXOR is a very fast (but weak) analog of `math/rand.Uint32`.

func (*PRNG) Uint32AddRotate

func (prng *PRNG) Uint32AddRotate() uint32

Uint32AddRotate is a very fast (but weak) analog of `math/rand.Uint32`.

func (*PRNG) Uint32AddRotateMultiply

func (prng *PRNG) Uint32AddRotateMultiply() uint32

Uint32AddRotateMultiply is a fast analog of `math/rand.Uint32`.

The reliability on statistical tests of this method is unknown. This is improved LCG method, so see also Uint32MultiplyAdd.

func (*PRNG) Uint32MultiplyAdd

func (prng *PRNG) Uint32MultiplyAdd() uint32

Uint32MultiplyAdd is a fast (but week) analog of `math/rand.Uint32`.

See also: https://en.wikipedia.org/wiki/Linear_congruential_generator

func (*PRNG) Uint32Xorshift

func (prng *PRNG) Uint32Xorshift() uint32

Uint32Xorshift is a very fast (but weak) analog of `math/rand.Uint32`.

See also: https://en.wikipedia.org/wiki/Xorshift

func (*PRNG) Uint64AddIfShiftXOR

func (prng *PRNG) Uint64AddIfShiftXOR() uint64

Uint64AddIfShiftXOR is a very fast (but weak) analog of `math/rand.Uint64`.

func (*PRNG) Uint64AddNRotateMultiply

func (prng *PRNG) Uint64AddNRotateMultiply() uint64

Uint64AddNRotateMultiply is a fast analog of `math/rand.Uint64`.

The reliability on statistical tests of this method is unknown. This is improved LCG method, so see also Uint64MultiplyAdd.

func (*PRNG) Uint64AddRotate

func (prng *PRNG) Uint64AddRotate() uint64

Uint64AddRotate is a very fast (but weak) analog of `math/rand.Uint64`.

func (*PRNG) Uint64AddRotateMultiply

func (prng *PRNG) Uint64AddRotateMultiply() uint64

Uint64AddRotateMultiply is a fast analog of `math/rand.Uint64`.

The reliability on statistical tests of this method is unknown. This is improved LCG method, so see also Uint64MultiplyAdd.

func (*PRNG) Uint64CpuTicks

func (prng *PRNG) Uint64CpuTicks() uint64

Uint64CpuTicks returns current value of ticks count on AMD64 CPU

func (*PRNG) Uint64MSWS

func (prng *PRNG) Uint64MSWS() uint64

See also: https://en.wikipedia.org/wiki/Middle-square_method

func (*PRNG) Uint64MultiplyAdd

func (prng *PRNG) Uint64MultiplyAdd() uint64

Uint64MultiplyAdd is a fast (but week) analog of `math/rand.Uint64`.

See also: https://en.wikipedia.org/wiki/Linear_congruential_generator

func (*PRNG) Uint64Xorshift

func (prng *PRNG) Uint64Xorshift() uint64

Uint64Xorshift is a very fast (but weak) analog of `math/rand.Uint64`.

See also: https://en.wikipedia.org/wiki/Xorshift

func (*PRNG) Uint64Xoshiro256

func (prng *PRNG) Uint64Xoshiro256() (result uint64)

See also: https://en.wikipedia.org/wiki/Xorshift#xoshiro_and_xoroshiro

func (*PRNG) XORReadUint32AddIfShiftXOR

func (prng *PRNG) XORReadUint32AddIfShiftXOR(b []byte) (l int, err error)

XORReadUint32AddIfShiftXOR XORs argument "b" with a pseudo-random value. The result is the same (but faster) as:

x := make([]byte, len(b))
mathrand.ReadUint32AddIfShiftXOR(x)
for i := range b {
	b[i] ^= x[i]
}

func (*PRNG) XORReadUint32AddIfShiftXORWithReseed

func (prng *PRNG) XORReadUint32AddIfShiftXORWithReseed(b []byte) (l int, err error)

XORReadUint32AddIfShiftXORWithReseed XORs argument "b" with a pseudo-random value. The result is the same (but faster) as:

x := make([]byte, len(b))
mathrand.ReadUint32AddIfShiftXORWithReseed(x)
for i := range b {
	b[i] ^= x[i]
}

func (*PRNG) XORReadUint32AddRotate

func (prng *PRNG) XORReadUint32AddRotate(b []byte) (l int, err error)

XORReadUint32AddRotate XORs argument "b" with a pseudo-random value. The result is the same (but faster) as:

x := make([]byte, len(b))
mathrand.ReadUint32AddRotate(x)
for i := range b {
	b[i] ^= x[i]
}

func (*PRNG) XORReadUint32AddRotateMultiply

func (prng *PRNG) XORReadUint32AddRotateMultiply(b []byte) (l int, err error)

XORReadUint32AddRotateMultiply XORs argument "b" with a pseudo-random value. The result is the same (but faster) as:

x := make([]byte, len(b))
mathrand.ReadUint32AddRotateMultiply(x)
for i := range b {
	b[i] ^= x[i]
}

func (*PRNG) XORReadUint32AddRotateMultiplyWithReseed

func (prng *PRNG) XORReadUint32AddRotateMultiplyWithReseed(b []byte) (l int, err error)

XORReadUint32AddRotateMultiplyWithReseed XORs argument "b" with a pseudo-random value. The result is the same (but faster) as:

x := make([]byte, len(b))
mathrand.ReadUint32AddRotateMultiplyWithReseed(x)
for i := range b {
	b[i] ^= x[i]
}

func (*PRNG) XORReadUint32AddRotateWithReseed

func (prng *PRNG) XORReadUint32AddRotateWithReseed(b []byte) (l int, err error)

XORReadUint32AddRotateWithReseed XORs argument "b" with a pseudo-random value. The result is the same (but faster) as:

x := make([]byte, len(b))
mathrand.ReadUint32AddRotateWithReseed(x)
for i := range b {
	b[i] ^= x[i]
}

func (*PRNG) XORReadUint32MultiplyAdd

func (prng *PRNG) XORReadUint32MultiplyAdd(b []byte) (l int, err error)

XORReadUint32MultiplyAdd XORs argument "b" with a pseudo-random value. The result is the same (but faster) as:

x := make([]byte, len(b))
mathrand.ReadUint32MultiplyAdd(x)
for i := range b {
	b[i] ^= x[i]
}

func (*PRNG) XORReadUint32MultiplyAddWithReseed

func (prng *PRNG) XORReadUint32MultiplyAddWithReseed(b []byte) (l int, err error)

XORReadUint32MultiplyAddWithReseed XORs argument "b" with a pseudo-random value. The result is the same (but faster) as:

x := make([]byte, len(b))
mathrand.ReadUint32MultiplyAddWithReseed(x)
for i := range b {
	b[i] ^= x[i]
}

func (*PRNG) XORReadUint32PCG

func (prng *PRNG) XORReadUint32PCG(b []byte) (l int, err error)

XORReadUint32PCG XORs argument "b" with a pseudo-random value. The result is the same (but faster) as:

x := make([]byte, len(b))
mathrand.ReadUint32PCG(x)
for i := range b {
	b[i] ^= x[i]
}

func (*PRNG) XORReadUint32PCGWithReseed

func (prng *PRNG) XORReadUint32PCGWithReseed(b []byte) (l int, err error)

XORReadUint32PCGWithReseed XORs argument "b" with a pseudo-random value. The result is the same (but faster) as:

x := make([]byte, len(b))
mathrand.ReadUint32PCGWithReseed(x)
for i := range b {
	b[i] ^= x[i]
}

func (*PRNG) XORReadUint32Xorshift

func (prng *PRNG) XORReadUint32Xorshift(b []byte) (l int, err error)

XORReadUint32Xorshift XORs argument "b" with a pseudo-random value. The result is the same (but faster) as:

x := make([]byte, len(b))
mathrand.ReadUint32Xorshift(x)
for i := range b {
	b[i] ^= x[i]
}

func (*PRNG) XORReadUint32XorshiftWithReseed

func (prng *PRNG) XORReadUint32XorshiftWithReseed(b []byte) (l int, err error)

XORReadUint32XorshiftWithReseed XORs argument "b" with a pseudo-random value. The result is the same (but faster) as:

x := make([]byte, len(b))
mathrand.ReadUint32XorshiftWithReseed(x)
for i := range b {
	b[i] ^= x[i]
}

func (*PRNG) XORReadUint64AddIfShiftXOR

func (prng *PRNG) XORReadUint64AddIfShiftXOR(b []byte) (l int, err error)

XORReadUint64AddIfShiftXOR XORs argument "b" with a pseudo-random value. The result is the same (but faster) as:

x := make([]byte, len(b))
mathrand.ReadUint64AddIfShiftXOR(x)
for i := range b {
	b[i] ^= x[i]
}

func (*PRNG) XORReadUint64AddIfShiftXORWithReseed

func (prng *PRNG) XORReadUint64AddIfShiftXORWithReseed(b []byte) (l int, err error)

XORReadUint64AddIfShiftXORWithReseed XORs argument "b" with a pseudo-random value. The result is the same (but faster) as:

x := make([]byte, len(b))
mathrand.ReadUint64AddIfShiftXORWithReseed(x)
for i := range b {
	b[i] ^= x[i]
}

func (*PRNG) XORReadUint64AddNRotateMultiply

func (prng *PRNG) XORReadUint64AddNRotateMultiply(b []byte) (l int, err error)

XORReadUint64AddNRotateMultiply XORs argument "b" with a pseudo-random value. The result is the same (but faster) as:

x := make([]byte, len(b))
mathrand.ReadUint64AddNRotateMultiply(x)
for i := range b {
	b[i] ^= x[i]
}

func (*PRNG) XORReadUint64AddNRotateMultiplyWithReseed

func (prng *PRNG) XORReadUint64AddNRotateMultiplyWithReseed(b []byte) (l int, err error)

XORReadUint64AddNRotateMultiplyWithReseed XORs argument "b" with a pseudo-random value. The result is the same (but faster) as:

x := make([]byte, len(b))
mathrand.ReadUint64AddNRotateMultiplyWithReseed(x)
for i := range b {
	b[i] ^= x[i]
}

func (*PRNG) XORReadUint64AddRotate

func (prng *PRNG) XORReadUint64AddRotate(b []byte) (l int, err error)

XORReadUint64AddRotate XORs argument "b" with a pseudo-random value. The result is the same (but faster) as:

x := make([]byte, len(b))
mathrand.ReadUint64AddRotate(x)
for i := range b {
	b[i] ^= x[i]
}

func (*PRNG) XORReadUint64AddRotateMultiply

func (prng *PRNG) XORReadUint64AddRotateMultiply(b []byte) (l int, err error)

XORReadUint64AddRotateMultiply XORs argument "b" with a pseudo-random value. The result is the same (but faster) as:

x := make([]byte, len(b))
mathrand.ReadUint64AddRotateMultiply(x)
for i := range b {
	b[i] ^= x[i]
}

func (*PRNG) XORReadUint64AddRotateMultiplyWithReseed

func (prng *PRNG) XORReadUint64AddRotateMultiplyWithReseed(b []byte) (l int, err error)

XORReadUint64AddRotateMultiplyWithReseed XORs argument "b" with a pseudo-random value. The result is the same (but faster) as:

x := make([]byte, len(b))
mathrand.ReadUint64AddRotateMultiplyWithReseed(x)
for i := range b {
	b[i] ^= x[i]
}

func (*PRNG) XORReadUint64AddRotateWithReseed

func (prng *PRNG) XORReadUint64AddRotateWithReseed(b []byte) (l int, err error)

XORReadUint64AddRotateWithReseed XORs argument "b" with a pseudo-random value. The result is the same (but faster) as:

x := make([]byte, len(b))
mathrand.ReadUint64AddRotateWithReseed(x)
for i := range b {
	b[i] ^= x[i]
}

func (*PRNG) XORReadUint64MSWS

func (prng *PRNG) XORReadUint64MSWS(b []byte) (l int, err error)

XORReadUint64MSWS XORs argument "b" with a pseudo-random value. The result is the same (but faster) as:

x := make([]byte, len(b))
mathrand.ReadUint64MSWS(x)
for i := range b {
	b[i] ^= x[i]
}

func (*PRNG) XORReadUint64MSWSWithReseed

func (prng *PRNG) XORReadUint64MSWSWithReseed(b []byte) (l int, err error)

XORReadUint64MSWSWithReseed XORs argument "b" with a pseudo-random value. The result is the same (but faster) as:

x := make([]byte, len(b))
mathrand.ReadUint64MSWSWithReseed(x)
for i := range b {
	b[i] ^= x[i]
}

func (*PRNG) XORReadUint64MultiplyAdd

func (prng *PRNG) XORReadUint64MultiplyAdd(b []byte) (l int, err error)

XORReadUint64MultiplyAdd XORs argument "b" with a pseudo-random value. The result is the same (but faster) as:

x := make([]byte, len(b))
mathrand.ReadUint64MultiplyAdd(x)
for i := range b {
	b[i] ^= x[i]
}

func (*PRNG) XORReadUint64MultiplyAddWithReseed

func (prng *PRNG) XORReadUint64MultiplyAddWithReseed(b []byte) (l int, err error)

XORReadUint64MultiplyAddWithReseed XORs argument "b" with a pseudo-random value. The result is the same (but faster) as:

x := make([]byte, len(b))
mathrand.ReadUint64MultiplyAddWithReseed(x)
for i := range b {
	b[i] ^= x[i]
}

func (*PRNG) XORReadUint64Xorshift

func (prng *PRNG) XORReadUint64Xorshift(b []byte) (l int, err error)

XORReadUint64Xorshift XORs argument "b" with a pseudo-random value. The result is the same (but faster) as:

x := make([]byte, len(b))
mathrand.ReadUint64Xorshift(x)
for i := range b {
	b[i] ^= x[i]
}

func (*PRNG) XORReadUint64XorshiftWithReseed

func (prng *PRNG) XORReadUint64XorshiftWithReseed(b []byte) (l int, err error)

XORReadUint64XorshiftWithReseed XORs argument "b" with a pseudo-random value. The result is the same (but faster) as:

x := make([]byte, len(b))
mathrand.ReadUint64XorshiftWithReseed(x)
for i := range b {
	b[i] ^= x[i]
}

func (*PRNG) XORReadUint64Xoshiro256

func (prng *PRNG) XORReadUint64Xoshiro256(b []byte) (l int, err error)

XORReadUint64Xoshiro256 XORs argument "b" with a pseudo-random value. The result is the same (but faster) as:

x := make([]byte, len(b))
mathrand.ReadUint64Xoshiro256(x)
for i := range b {
	b[i] ^= x[i]
}

func (*PRNG) XORReadUint64Xoshiro256WithReseed

func (prng *PRNG) XORReadUint64Xoshiro256WithReseed(b []byte) (l int, err error)

XORReadUint64Xoshiro256WithReseed XORs argument "b" with a pseudo-random value. The result is the same (but faster) as:

x := make([]byte, len(b))
mathrand.ReadUint64Xoshiro256WithReseed(x)
for i := range b {
	b[i] ^= x[i]
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL