Random Number Generator
Generate random numbers within any range, with options for uniqueness.
About the Random Number Generator
This random number generator produces cryptographically secure random integers in any range you specify. Unlike quick generators that call Math.random() — a pseudo-random number generator with measurable statistical bias and no security guarantees — this tool uses crypto.getRandomValues(), which draws entropy directly from your operating system’s CSPRNG.
Random numbers drive an enormous range of applications: lotteries, A/B test assignment, statistical sampling, Monte Carlo simulations, game AI, CAPTCHA challenge selection, and cryptographic key generation. The right source of randomness depends on the use case — a child’s coin flip can use Math.random(), but a gambling site, a clinical trial randomization, or a security token must use a CSPRNG. This tool defaults to the CSPRNG so you do not have to remember the distinction.
The unique-value option generates a random sample without replacement — equivalent to drawing numbered balls from a bag. This is the correct mode for raffles, classroom random-callers, A/B test bucketing, and any scenario where repeating a number would be misleading or biased.
How It Works
Each draw requests one 32-bit unsigned integer (range 0 to 4,294,967,295) from crypto.getRandomValues(). The integer is reduced into the requested range using modulo: mn + (random_uint % range) where range = mx - mn + 1. This introduces a tiny modulo bias when range does not evenly divide 2^32 — for a range of 100, the bias is 100 / 2^32 ≈ 2.3 × 10^-8, negligible for non-cryptographic applications. For cryptographic use requiring zero bias, the standard rejection-sampling technique (re-draw when the random value falls in the topmost incomplete bucket) should be applied.
The unique-value mode maintains a JavaScript Set of previously drawn values. If the random draw produces a duplicate, it is discarded and the loop continues. This is an O(n) Fisher-Yates-style approach suitable for up to a few thousand values. For very large unique samples (10,000+), the algorithm degrades because the probability of drawing a duplicate rises as the set fills — generating 999,999 unique numbers from a range of one million takes roughly 14 million draws on average.
The maximum range supported is 2^32 - 1 (4,294,967,295). For larger ranges, the tool would need to combine multiple 32-bit draws into a 53-bit or 64-bit integer. Most practical use cases (lotteries, A/B tests, raffles) operate well within the 32-bit limit.
The summary statistics (sum, average, min, max) let you sanity-check the distribution. Over many runs with the same range and count, the average should converge to the midpoint of the range — a quick visual check that the generator is unbiased.
Worked Examples
Drawing 1 number between 1 and 100 typically produces something like 47. Drawing 6 unique numbers between 1 and 49 (the classic 6/49 lottery format used in Powerball and many national lotteries) might produce 3, 12, 17, 28, 31, 44. The unique-mode guarantee means none of these will repeat.
Drawing 100 numbers between 1 and 10 in unique mode is impossible (only 10 unique values exist) — the tool reports an error. Drawing 100 numbers between 1 and 100 in unique mode produces a permutation of the numbers 1 through 100, which is the basis of a Fisher-Yates shuffle.
For a Monte Carlo simulation estimating π, draw 10,000 pairs of (x, y) values in the range [0, 1]. Count how many fall inside the unit circle (x² + y² ≤ 1). The ratio × 4 converges to π as the sample grows. With 10,000 pairs you typically get 3.12-3.16 — close but not exact, demonstrating the law of large numbers.
For a raffle with 100 tickets numbered 1-100, drawing 3 unique numbers picks the winners. Each ticket has a 3% chance of being selected, with no ticket able to win twice.
When to Use This Tool
- Lottery and raffle draws where cryptographic fairness is required (avoiding any predictable PRNG).
- A/B test bucket assignment where users must be deterministically split into experiment groups without bias.
- Statistical sampling for surveys, audits, or quality control where each unit must have equal probability of selection.
- Game AI — dice rolls, card shuffles, NPC behavior randomization for board games and video games.
- CAPTCHA challenge selection where attackers must not predict which challenge will appear.
- Classroom random callers for fair student participation tracking.
- Monte Carlo simulations in physics, finance, and operations research.
Limitations & Disclaimer
This generator uses the Web Crypto API’s crypto.getRandomValues, which is a CSPRNG but technically pseudo-random (deterministic given the seed). The modulo reduction introduces a sub-1-in-a-billion bias that is negligible for statistical use but should be eliminated via rejection sampling for cryptographic key generation. The 32-bit per-draw ceiling limits the maximum range to ~4.3 billion. Unique-value mode uses a Set-based approach that becomes inefficient as the requested count approaches the range size. For high-stakes randomness (gambling, clinical trials, cryptographic key generation), use a hardware RNG certified to your jurisdiction’s standards. See our disclaimer for full terms.
Frequently Asked Questions
Is this generator truly random?
It uses <code>crypto.getRandomValues</code>, which is a CSPRNG that draws from your operating system’s entropy pool. On Linux this is <code>/dev/urandom</code>, on macOS the kernel’s <code>ccdrbg</code>, on Windows <code>BCryptGenRandom</code>. These are technically pseudo-random (deterministic given the seed) but indistinguishable from true randomness for any practical purpose and pass NIST SP800-22 statistical tests.
What is modulo bias and does it matter?
When you take <code>random_uint % range</code>, values below the next multiple of <code>range</code> are slightly more likely than values above it. For a range of 100 and a 32-bit source, the bias is ~2.3 in a billion — negligible for non-cryptographic use. For cryptographic applications (key generation, IVs), the standard mitigation is rejection sampling: if the random value is in the topmost partial bucket, discard and redraw.
How is this different from Math.random?
<code>Math.random</code> uses a fast non-cryptographic PRNG (often xorshift128+ in V8) optimized for animation and games. Its output can be predicted from observing prior outputs, and several browser engines have had statistical anomalies. <code>crypto.getRandomValues</code> is designed for security-sensitive use, draws from the OS entropy pool, and cannot be predicted from prior outputs.
What is the maximum range I can use?
The theoretical maximum is <code>2^32 - 1</code> (4,294,967,295) because the tool requests a 32-bit unsigned integer per draw. For most practical use cases this is more than sufficient. If you need larger ranges (e.g., 64-bit identifiers), use a dedicated 64-bit CSPRNG library.
Why does unique mode sometimes fail?
When the requested count exceeds the available range, unique mode cannot succeed. Drawing 100 unique numbers from a range of 50 is mathematically impossible. The tool checks this upfront and reports an error rather than silently repeating values. For ranges close to the count, generation may take longer as the set fills and duplicate draws become more frequent.
Can I use this for gambling or lottery applications?
From a randomness standpoint, yes — the CSPRNG output is unbiased. From a legal standpoint, most jurisdictions require licensed random-number generators with audited seeds, dedicated hardware, and witnessing procedures. Browser-based generators do not meet those regulatory requirements. Use this tool for prototyping and analysis; use a certified HSM-based RNG for production gambling systems.
Last updated: July 21, 2026 · Author: HT99 Tools Editorial Team · Reviewed by: HT99 Tools Editorial Team