kelindar / xxrand

Fast, scalable pseudo random number generator based on xxh3
MIT License
10 stars 1 forks source link

kelindar/xxrand
Go Version PkgGoDev Go Report Card License Coverage

XXH3-Based Pseudorandom Number Generator

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.

Features

What is this for?

Benchmark Results

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