Experiment - fast PRNG implementations in .NET. Your PRNG is unlikely to be a bottleneck in anything you do, but there are exceptions like for instance Monte Carlo simulations, where generating random samples can take some time.
To be clear - there is little original work here, only .NET implementations of existing algorithms. Mainly for learning/curiosity purposes.
Sources:
- https://prng.di.unimi.it/
- https://espadrine.github.io/blog/posts/shishua-the-fastest-prng-in-the-world.html
The benchmarks measure generation of double
s.
Iterations = double
s per op.
There is likely overhead in capturing hardware counters, so these should be more "correct"
- Zero allocations (vectorized PRNGs may allocate during constructions since they may be buffered, see Shishua)
- Implemented as
struct
s - cache locality - Inline as much as possible - no virtual calls/indirection (and if something isn't inlined, the above also helps)
- No abstraction - interfaces etc, makes it easier to not invalidate the above
- Vectorization where possible - beneficial if PRNG is on your hotpath
dotnet test -c Release --logger:"console;verbosity=detailed"
Plotly diagrams are generated during tests where distritution is compared to System.Random
as a baseline.
The goal is for the implemented PRNGs to match the (uniform) distribution of System.Random
.