Evaluating the "best" random number generator (RNG) is a complex task because the definition of "best" can vary depending on the specific application, the type of randomness required (e.g., true randomness for cryptography vs. pseudo-randomness for simulations), and the criteria used for evaluation (e.g., speed, entropy, distribution, pass rate in statistical tests). That said, I'll provide an overview of highly regarded random number generators across different categories, highlighting their performance in various tests:
1. True Random Number Generators (TRNGs) - For Cryptographic Applications
-
Fortuna PRNG with a TRNG seed (e.g., from hardware sources like thermal noise, photon arrival times, or radioactive decay events):
- Tests and Performance: Typically passes all relevant statistical tests (e.g., Diehard, TestU01, NIST Statistical Test Suite) due to its high entropy source. Fortuna's design ensures that it can effectively harness and stretch the entropy from a TRNG, making it highly secure for cryptographic purposes.
- Implementation Notes: The quality of the TRNG output is paramount. Fortuna is a well-regarded PRNG framework when seeded with high-quality entropy. For example, Intel's Secure Key technology uses a TRNG to seed its RNG operations, demonstrating its use in hardware-based solutions.
- Example Use Case: Cryptographic key generation, secure authentication protocols.
-
Hardware Security Modules (HSMs) with integrated TRNGs:
- Tests and Performance: Custom and regulatory tests (e.g., FIPS 140-2, Common Criteria EAL4+). These consistently show high randomness quality, as HSMs are designed to meet stringent security standards.
- Implementation Notes: HSMs integrate TRNGs with advanced physical security measures, ensuring the generated randomness is both of high quality and protected from tampering.
- Example Use Case: Secure key storage, transaction processing in financial systems.
2. Pseudo-Random Number Generators (PRNGs) - For General and Simulation Purposes
-
Xorshift Generators (e.g., xorshift128+):
- Tests and Performance: Passes BigCrush (part of TestU01), a stringent test suite. Shows excellent speed and decent statistical quality. Xorshift generators are known for their simplicity and high performance, making them suitable for applications where speed is critical.
- Implementation Notes: Simple to implement and very fast, Xorshift is widely used in simulations, games, and other high-throughput applications. However, it may not be suitable for cryptographic purposes due to its predictability.
- Example Use Case: Monte Carlo simulations, video games.
-
****PCG (Permuted Congruential Generator):
- Tests and Performance: Designed to pass BigCrush and PractRand, demonstrating excellent statistical properties and speed. PCG offers a better balance between quality and performance compared to older generators like LCGs.
- Implementation Notes: Offers a good balance between speed and quality, suitable for a wide range of applications. PCG allows for customization, such as choosing different permutation functions, which can be tailored to specific use cases.
- Example Use Case: Statistical modeling, scientific simulations.
-
****ChaCha20 (as a PRNG, not in its primary use as a stream cipher):
- Tests and Performance: Passes PractRand and BigCrush, showing its robustness in generating pseudo-random numbers. ChaCha20's cryptographic origins ensure high-quality output, though it is slower than Xorshift or PCG for PRNG purposes.
- Implementation Notes: While slower than other PRNGs, its security properties make it a good choice when a PRNG with a strong cryptographic backbone is needed but a full TRNG is not required.
- Example Use Case: Simulations requiring high randomness quality, non-cryptographic applications where security is still a consideration.
Key Tests Mentioned:
- Diehard Tests: A battery of statistical tests for RNGs, focusing on randomness quality.
- TestU01 (Specifically BigCrush): A more comprehensive and stringent test suite than Diehard, pushing the limits of RNGs.
- NIST Statistical Test Suite: Used to evaluate RNGs for cryptographic applications, focusing on security.
- PractRand: Tests RNGs for practical use, evaluating both the statistical quality and the period length.
Conclusion:
-
For Cryptographic Purposes: A well-implemented Fortuna PRNG seeded with a high-quality TRNG or a Hardware Security Module (HSM) with a built-in TRNG is considered best due to their focus on security and entropy.
-
For General and Simulation Purposes: PCG (Permuted Congruential Generator) is often highlighted for its excellent balance between statistical quality and speed, making it versatile across various applications.
Important Note: The "best" RNG can also depend on implementation details, platform constraints, and the specific requirements of your project. Always evaluate RNGs in the context of your particular use case.