romu - Rust crate
A pseudo random number generator using the algorithm Romu for the programing language Rust.
This pseudo random number generator (PRNG) is not intended for cryptographic purposes. This crate only implements the 64-bit "RomuTrio" generator, since it's the recommended generator by the original author.
Non-linear random number generator
Romu is a non-linear random number generator. That means that the period is probabilistic and is based on the seed. The bigger the needed period is, the higher the chance it is that the actual period is "too small".
Following formula is given by the author:
P(|cycle contains x<= 2^k|) = 2^k-s+7
k is size of random numbers needed + 1.
s is the state size.
Example chances for getting a "too small" period:
- When 262 * 64-bit numbers are needed (32 EiB) -> 2-122 chance
- When 239 * 64-bit numbers are needed (4 TiB) -> 2-146 chance
- When 236 * 64-bit numbers are needed (512 GiB) -> 2-149 chance
You can read more about the theory behind Romu in the official paper and it's unique selling points on the official website of the original author.
Features
The crate is no_std compatible.
std- Ifgetrandomis not used or returns an error, the generator will use the thread name and the current instance time to create a seed value. Enabled by default.tls- Creates static functions that use a thread local version of the generator. Enabled by default.getrandom- Uses thegetrandomcrate to create a seed of high entropy. Enabled by default.unstable_tls- Uses the unstablethread_localfeature of Rust nightly. Improves the call times to the thread local functions greatly.unstable_simd- Uses the unstablestd::simdcrate of Rust nightly to provide special SIMD versions of the generator which can be used to create large amount of random data fast.
SIMD
The unstable_simd feature activates the types Rng128, Rng256, Rng512 for 2 lane, 4 lane and 8 lane SIMD
respectively. From my limited testing it seems that speed improvements can only be seen once AVX2 is activated and
at least "Rng256" is used:
License
Licensed under Apache License, Version 2.0, (LICENSE or http://www.apache.org/licenses/LICENSE-2.0).
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license without any additional terms or conditions.