What is Pseudo-Random vs. True Random Number Generation?
Mathematical Foundation
Laws & Principles
- Determinism: Every PRNG is fully deterministic. Given the same seed value, the exact same sequence of numbers is always produced. This is why software random number generators used in games, simulations, and statistical sampling are called 'pseudo-random' — they are mathematically reproducible. High-level runtime environments like JavaScript use implementation-defined PRNGs seeded by OS entropy.
- CSPRNG for Security: Standard PRNGs are NOT suitable for cryptographic use (passwords, tokens, encryption keys) because their internal state can be reverse-engineered from their output. Cryptographically Secure PRNGs (CSPRNGs) use entropy sources like hardware timing jitter, mouse movement, or CPU thermal noise to seed a hash-based generator that is computationally infeasible to predict.
Step-by-Step Example Walkthrough
" Generating a random integer between 1 and 100 using a uniform distribution. "
- 1. Get a raw random float: The engine returns a pseudo-random value in [0, 1).
- 2. Scale to range: Multiply the float by (maximum - minimum + 1) = 100.
- 3. Shift by minimum: Add the minimum offset (1) so the range becomes [1, 101).
- 4. Floor to integer: Truncate the decimals to yield a flat [1, 100] distribution.