Computational Foundations: PRNG vs CSPRNG vs True Hardware Entropy
How modern computing architectures generate, scale, and validate unbiased random numbers.
Computers are inherently deterministic finite-state machines. Generating "random" numbers requires either capturing physical non-deterministic external noise (True Random Number Generators - TRNG) or expanding an initial seed state through non-linear mathematical transformations (Pseudo-Random Number Generators - PRNG).
Basic Simulation Engine
Formula X_(n+1) = (aX_n + c) mod m. Highly vulnerable to Marsaglia's theorem (points falling into parallel hyperplanes). Fast, but cryptographically broken.
Scientific Monte Carlo
Astronomical period of 2¹⁹⁹³⁷ - 1 with 623-dimensional equidistribution. Ideal for physics simulations, but predictable after observing 624 outputs.
Cryptographic Security
Powered by crypto.getRandomValues using ChaCha20/AES-CTR with OS entropy pooling. Unpredictable even under full adversary inspection.
Random Number Generator Algorithms Reference Matrix
Comparing periodicity, NIST statistical suite compliance, and cryptographic resilience.
| Algorithm / Source | Period Length | NIST / Dieharder | Crypto Security | Primary Application |
|---|---|---|---|---|
| Web Crypto API (ChaCha20) | 2⁷³ bytes | 100% Pass | Yes (CSPRNG) | Raffles, Giveaways, Key generation, Lotteries |
| Mersenne Twister (MT19937) | 2¹⁹⁹³⁷ - 1 | Pass (Non-crypto) | No | Scientific modeling, Game physics, Monte Carlo |
| xorshift128+ (V8 Engine) | 2¹²⁸ - 1 | Minor Failures | No | Default browser Math.random() implementation |
| Linear Congruential (ANSI C) | 2³² | Fail | No | Legacy embedded systems, simple non-critical code |
| Hardware TRNG (Thermal Noise) | Infinite (Aperiodic) | 100% Pass | Yes (Hardware) | OS entropy pools (/dev/urandom), CPU RDRAND |
Modulo Bias Elimination via Rejection Sampling
Why naïve modulo formulas introduce statistical favoritism and how to eliminate it.
When scaling a 32-bit random integer (range 0 \dots 2³² - 1 = 4,294,967,295) to a custom window of size R, developers frequently use the modulo operator val % R. However, unless R is an exact power of two, 2³² is not evenly divisible by R. The remainder values at the bottom of the range receive an extra possible outcome, systematically biasing draws toward lower numbers.
limit = (2³² - (2³² % range))
do { raw = crypto.getRandomValues(uint32)[0]; } while (raw >= limit);
return min + (raw % range);
By discarding the negligible slice of values greater than or equal to limit, every integer in the designated window receives an identically equal probability of selection down to absolute mathematical parity.
Sampling With Replacement vs Fisher-Yates Permutations
How unique number generation operates without performance degradation or infinite loops.
Sampling With Replacement
Independent DrawsEach draw has zero memory of previous numbers. The probability of picking any specific value remains constant at 1 / (Max - Min + 1). Duplicates naturally occur according to the Birthday Paradox.
Sampling Without Replacement
Fisher-Yates ShuffleGuarantees that every generated number in the batch is strictly unique. Utilizes the O(k) modern Fisher-Yates partial shuffle to extract unbiased items in linear time without retry stalls.
Worked Case Studies & Probabilistic Scenarios
Concrete practical applications in giveaways, scientific trials, and statistical tests.
Scenario 1: Verifiable Contest Raffle — 3 Unique Winners from 1,250 Entries
Contest AuditAn organization has 1,250 numbered ticket entries (#1 to #1250) and must select 3 distinct grand prize winners without duplicate selections.
Scenario 2: Clinical Trial Randomized Treatment Allocation (A vs B)
Medical ResearchA medical research team must randomly allocate 20 enrolled patients to either Treatment Arm A (assigned to odd integers) or Control Arm B (assigned to even integers) between 1 and 100.
Scenario 3: Chi-Square Uniformity Test — Validating 10,000 Draws
Statistical QualityTo verify that numbers between 1 and 10 are uniformly distributed, 10,000 iterations are run and grouped into 10 buckets (Expected frequency E = 1,000 per bucket).
How to Generate Random Numbers Step-by-Step
Follow these four simple steps to configure and generate uniform random numbers.
Set Range Boundaries (Min & Max)
Define the minimum and maximum integer values for your target random number generation window.
Specify Quantity & Duplication Rules
Choose how many numbers to generate and check or uncheck 'Allow Duplicates' depending on whether you require unique items.
Execute Random Generation
Click Generate to trigger the cryptographic PRNG engine and immediately receive uniformly distributed values.
Copy, Sort, or Export Numbers
Sort outcomes numerically, inspect sequence statistics, or copy the comma-delimited output directly to your clipboard.
Frequently Asked Questions
Everything you need to know about modulo bias, sampling methods, and cryptographic entropy.
How does the random number generator prevent modulo bias?
Instead of a simple modulo operator which over-represents lower numbers when the range does not evenly divide 2^32, the engine employs rejection sampling to discard out-of-bounds entropy words before scaling.
What is the difference between sampling with replacement versus without replacement?
Sampling with replacement treats each draw independently, allowing numbers to repeat. Sampling without replacement (disallowing duplicates) utilizes the Fisher-Yates shuffle algorithm to guarantee that every selected number in the batch is strictly unique.
Is this RNG suitable for cryptographic key generation and sensitive lotteries?
Yes. The generator interfaces directly with the browser's Web Cryptography API (crypto.getRandomValues), drawing high-entropy seeds directly from operating system hardware sources rather than deterministic math algorithms.
What are the maximum and minimum boundaries for integer generation?
You can generate integers spanning from negative 1,000,000,000 to positive 1,000,000,000, with batch sizes up to 1,000 unique values per calculation cycle.
Does generating random numbers send my data or results to remote servers?
No. All random number generation routines, array permutations, and uniqueness validations execute 100% on the client side in your web browser with complete privacy.