Description
pgregory.net/rand is a Go random number package that is meant as a faster, higher-quality replacement for math/rand and the experimental golang.org/x/exp/rand. It keeps the API of *rand.Rand and most top-level functions, so existing code can often switch to it with an import change. It removes the top-level Seed function and the Source interface, and makes setup simpler: rand.New() creates a generator seeded from the clock, and rand.New(1) gives a fixed seed. The README includes benchmarks against math/rand, math/rand/v2, golang.org/x/exp/rand and fastrand on Intel and Xeon CPUs, and notes that fastrand does not produce good random numbers. The FAQ explains the author's reasons for writing it and says that math/rand/v2 is the better choice unless every nanosecond counts, in which case this package is still faster without losing quality. It is for Go developers who use random numbers in simulations, tests, games or other hot code paths. It is a library, so you add it to a Go module and import it.…
Highlights
- API-compatible with most of math/rand
- Faster and higher quality, per the benchmarks
- Simpler generator creation with rand.New()
- No top-level Seed function or Source interface
- Benchmarks against several Go random packages
Ratings & Reviews
No ratings yet
Be the first to rate Rand.
People also visit
Rand FAQ
What is this package?
A Go random number library that aims to be a faster, higher-quality drop-in for most of math/rand.
How is it different from math/rand?
It keeps the same methods, drops Seed and the Source interface, and makes creating a generator simpler.
Should I use it instead of math/rand/v2?
The author suggests math/rand/v2 unless you are counting nanoseconds. If you are, this package is still faster.
How do I start?
Import pgregory.net/rand, then call rand.New() for a time-seeded generator or rand.New(1) for a fixed seed.
Is the source public?
Yes. The package is published on GitHub, with its benchmarks and FAQ in the README.
What are the best Rand alternatives?
Popular alternatives to Rand include Primesieve and Rust Algorithms. See all Rand alternatives




