Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The best choice for random number generator

Tags:

random

haskell

There are so many randomizers out there. Some standard ones are questionably slow. Some claim to be of high quality and speed. Some claim to be of higher quality. Some claim to be even more fast and of better quality. Some claim the speed but quality.

One fact I know is that mwc-random is being used by the Criterion benchmarking library which speaks for itself and the claims are very promising.

Since there are at least two qualities to every generator: the robustness and the quality of the generated number - I'll split the question of choosing the best generator into three categories:

  1. The fastest
  2. The one generating the most random number
  3. The one having the optimal combination of both of these qualities at adequate rate

So which is which and why?

like image 266
Nikita Volkov Avatar asked Feb 22 '23 16:02

Nikita Volkov


1 Answers

I only can speak about mwc-random.

  1. It is fast ~15ns per Word32 on Phenom II. If you want to measure how fast is it on your computer it comes with benchmark set. Still it possible to trade period for speed. Xorshift RNG should be faster but have shorter periods 2^32 or 2^64 instead of 2^8222.

  2. Randomness. mwc-random uses algorithm MWC256 (another name: MWC8222) which is not cryptographicaly secure but fares well in randomness tests. In particular mwc-random passes dieharder randomness test.

like image 196
Shimuuar Avatar answered Mar 05 '23 17:03

Shimuuar