Alternatives to rand()
I recently added some functionality for random number generation to my modules, which led me on a digression about rand(). This is a short look at some modules for getting random floating point values. A later one will look at random ints and bytes.
Module Algorithm |
Stat Quality |
Interval | Bits in output |
Auto Seed |
Predictable | Speed |
---|---|---|---|---|---|---|
CORE::rand drand48 |
Bad | [0,1) | 48 | OK | Yes | 29000 k/s |
Math::Random::MTwist MT XS |
OK | [0,1) | 53 | OK | Yes | 14000 k/s |
ntheory ChaCha20 XS |
Good | [0,1) | 53-113 | Full | No | 12000 k/s |
Math::Prime::Util::GMP ISAAC XS |
Good | [0,1) | 53-64 | Good | No | 14000 k/s |
Crypt::PRNG Fortuna XS |
Good | [0,1) | 53 | Good | No | 700 k/s |
Math::Random::MT::Auto MT XS |
OK | [0,1) | 52 | Full | Yes | 5000 k/s |
Math::Random::MT MT XS |
OK | [0,1) | 32 | rand() | Yes | 2200 k/s |
Math::Random::Secure Math::Random::ISAAC |
Good | [0,1) | 32 | Full | No | 460 k/s |
Math::Random::ISAAC ISAAC XS or PP |
Good | [0,1] | 32 | None | No | 5700 k/s 480 k/s |
Math::Random::Xorshift Xorshift XS |
OK | [0,1] | 32 | Time | Yes | 16000 k/s |