1. The Computer Science Problem of Randomness
Computers are fundamentally deterministic machines: given the exact same initial state and input instruction, a computer processor will always produce the exact same output. Creating authentic unpredictability inside software has therefore challenged computer scientists since the dawn of computing.
In the physical world, we rely on mechanical systems like rolling dice, tossing coins, or shuffling cards. However, even physical devices are subject to physical imperfections: dice faces can have uneven weight distribution due to carved pips, coins are slightly heavier on the heads side, and human card shuffles are frequently incomplete.
2. PRNG vs. CSPRNG: The Crucial Difference
In digital software, algorithms that generate numbers fall into two distinct classes:
1. Pseudo-Random Number Generators (PRNG): Standard libraries (including JavaScript's Math.random()) use mathematical formulas (such as XorShift128+ or Linear Congruential Generators) starting from an initial 'seed' number. While the sequence appears random at a glance, observing a small series of numbers allows an observer to deduce the internal state and predict every future number with 100% certainty.
2. Cryptographically Secure Pseudo-Random Number Generators (CSPRNG): Systems like the W3C Web Cryptography API's window.crypto.getRandomValues() continuously harvest high-entropy physical noise from the operating system (such as thermal sensor fluctuations, hardware interrupts, and microscopic CPU timing jitter). They pass rigorous statistical tests for randomness and are mathematically unpredictable.
NIST Special Publication 800-90A specifies approved mechanisms for random number generation using deterministic random bit generators grounded in entropy sources.
Source: NIST SP 800-90A Rev. 1: Recommendation for Random Number Generation (National Institute of Standards and Technology (NIST))3. The Hidden Flaw: Modulo Bias Explained
Even when a developer utilizes a secure entropy source, an improper mathematical implementation can introduce subtle, invisible favoritism known as 'modulo bias'.
Suppose you generate a random byte between 0 and 255 (256 possible outcomes), and you wish to select a winner among 6 candidates using the modulo operator: winner = randomByte % 6.
Notice the mathematical problem: 256 is not evenly divisible by 6 (256 = 42 * 6 + 4). The outcomes 0, 1, 2, and 3 will occur 43 times each, while outcomes 4 and 5 will occur only 42 times. The first four candidates have a 16.8% chance of winning, while the last two have only a 16.4% chance. Over thousands of draws, the first entries are statistically favored.
4. How Rejection Sampling Guarantees Fairness
To achieve true mathematical uniformity across any arbitrary number of participants, DrawLuma implements uniform rejection sampling across tools like the Random Number Generator, Roll Dice Online, Coin Flip Online, and Wheel of Names.
Instead of forcing a non-divisible range through the modulo operator, the algorithm determines the largest exact multiple of the participant count that fits within the 32-bit integer range (0 to 4,294,967,295). Any randomly generated value that falls outside this exact multiple is safely discarded, and a new sample is drawn.
This guarantees that every candidate index has precisely identical mathematical probability, down to the single least significant bit. To see how uniform distributions behave in practice, explore our companion guides on coin flip streaks and independence and dice probability distributions.
5. Browser-Local Entropy & SHA-256 Checksums
Once an outcome is generated, how can participants verify that a published receipt has not been tampered with?
DrawLuma bundles the draw outcome, participant list, chosen indices, and random seed into a structured JSON receipt, and calculates its SHA-256 cryptographic digest—a 64-character hexadecimal checksum (explained further in our provably fair giveaway guide).
A cryptographic hash functions as a tamper-evident integrity check: because SHA-256 is collision-resistant (per NIST FIPS 180-4), modifying even a single character in the participant roster or outcome completely alters the hash. However, a hash is distinct from an asymmetric digital signature; it verifies data integrity, but does not identify an author or prove the absence of unrecorded test runs unless coupled with an unedited live recording or pre-committed hash (see our About & Verification documentation).
Open Random Number Generator
Test uniform cryptographic random number generation across any custom range with verifiable receipts.
Frequently Asked Questions
Why shouldn't I use Math.random() for raffles and giveaways?
JavaScript's Math.random() is not cryptographically secure and can produce subtle statistical biases. It is intended for visual animations and casual games, not unbiased financial, competitive, or prize draws.
What is uniform distribution?
Uniform distribution is a probability distribution in which every possible outcome has an equal probability of occurring. For a draw with 10 people, each person must have an exact 1/10 (10%) probability.
Can someone predict a DrawLuma winner in advance?
No. DrawLuma uses window.crypto.getRandomValues(), which pulls entropy directly from the device's hardware-level noise sources at the exact moment of the spin, making pre-calculation computationally impossible.