This package contains an experimental implementation of a noise based pseudorandom number generator that scales with multiple CPUs and from my benchmarks around 10x faster than using math.Rand
. It uses xx3 algorithm to hash a counter, the default counter being the time stamp counter (using RDTSC
instruction). That being said, most of use-cases probably are better of with using math.Rand
since it should provide better randomness characteristics.
Int31n()
).math/rand
equivalent.math/rand
tends to create a lock contention, especially when you are benchmarking multiple goroutines in parallel and generating some random data as you go.cpu: Intel(R) Core(TM) i7-9700K CPU @ 3.60GHz
BenchmarkParallel/rand-001-8 394602625 3.023 ns/op 0 B/op 0 allocs/op
BenchmarkParallel/rand-008-8 360640208 3.130 ns/op 0 B/op 0 allocs/op
BenchmarkParallel/rand-032-8 368496836 3.492 ns/op 0 B/op 0 allocs/op
BenchmarkParallel/rand-128-8 392360864 3.041 ns/op 0 B/op 0 allocs/op
BenchmarkParallel/rand-512-8 388266206 3.043 ns/op 0 B/op 0 allocs/op
BenchmarkParallel/rand-2048-8 382660137 3.097 ns/op 0 B/op 0 allocs/op