Random Number Generator (2026)
Need a fair, unbiased number for a raffle, a game, a statistics sample, or a decision you don't want to overthink? This tool generates one or many random numbers within any range you choose, with options for no-repeat (unique) values, ascending sorting, and decimal precision — and below it, a genuinely deep, practical guide to how random number generation actually works, so you understand exactly what you're getting and when it is (and isn't) good enough to rely on.
It uses the browser's built-in pseudo-random number generator (PRNG), which is statistically fair for games, raffles, samples, and everyday decisions — but is not cryptographically secure. For passwords, encryption keys, or security tokens, always use a dedicated cryptographically secure generator instead (see the security section below).
Math.random(), which modern browser engines implement with the xorshift128+ algorithm — a fast, well-distributed pseudo-random number generator (PRNG) commonly used for non-security purposes. Each value is scaled and, for integers, floored into your chosen range using standard, bias-aware scaling. This page also documents true random number generators (TRNGs), cryptographically secure PRNGs (CSPRNGs), and when each is the right tool, based on standard computer-science and cryptography references (e.g. NIST SP 800-90A/B/C on random bit generation).
What Is a Random Number Generator?
A random number generator (RNG) is any system — hardware or software — that produces a sequence of numbers with no predictable pattern, ideally where every value within the allowed range has an equal chance of appearing. RNGs are foundational to computing: they power everything from dice-roll apps and lottery drawings to statistical sampling, video game physics, procedural content generation, scientific simulation, and cryptographic key generation.
- A good RNG produces a uniform distribution — every number in range is equally likely
- Software RNGs are almost always "pseudo-random," driven by a deterministic algorithm and a seed
- True randomness requires an unpredictable physical source (thermal noise, radioactive decay, etc.)
- Not all RNGs are equal — statistical quality and security guarantees vary by algorithm and use case
- General-purpose RNGs like this tool are fine for games and sampling, but not for cryptography
- The same range and quantity can be generated any number of times, with different results each time
True Random vs. Pseudo-Random Numbers
Pseudo-random number generators (PRNGs) use a deterministic mathematical formula to produce a long sequence of numbers that looks statistically random but is fully determined by an initial "seed" value. Given the same seed and algorithm, a PRNG always produces the exact same sequence — a property that is actually useful for reproducible testing, simulations, and procedurally generated game worlds.
True random number generators (TRNGs) instead sample an unpredictable physical process — electronic thermal noise, atmospheric radio static, radioactive decay timing, or even camera sensor noise — to produce values that cannot be reproduced or predicted, even with full knowledge of the generating system. TRNGs are slower and more resource-intensive to produce at scale, so they are typically used to seed PRNGs or to generate small amounts of high-value randomness (like cryptographic keys) rather than large volumes of numbers.
| Property | Pseudo-Random (PRNG) | True Random (TRNG) |
|---|---|---|
| Source | Deterministic algorithm + seed | Physical/unpredictable process |
| Reproducible? | Yes, with the same seed | No — never repeats |
| Speed | Very fast, low resource use | Slower, hardware-dependent |
| Best for | Games, sampling, simulations, testing | Cryptographic keys, high-security tokens |
| Example | Math.random(), Mersenne Twister, xorshift | Hardware entropy sources, atmospheric noise APIs |
How This Generator Works
This tool generates each number using the browser's native Math.random() function, which returns a floating-point value between 0 (inclusive) and 1 (exclusive) with a uniform distribution. To produce an integer within your chosen range, the formula is:
Example: range 1–100 → Math.random() returns 0.4732 → floor(0.4732 × 100) + 1 = 48
For "no duplicates" mode, the generator draws values one at a time and discards any repeat, continuing until it has collected the requested quantity of distinct numbers — mathematically equivalent to drawing numbered balls from a bag without replacement. Sorting, when enabled, simply orders the final result set; it does not affect which numbers were chosen.
Types of Random Number Generators
| Type | How It Works | Typical Use |
|---|---|---|
| Pseudo-Random (PRNG) | Deterministic formula seeded by a starting value | Games, apps, simulations, general use (this tool) |
| Cryptographically Secure PRNG (CSPRNG) | PRNG designed so outputs cannot be predicted from prior outputs | Passwords, session tokens, encryption keys |
| True Random (TRNG / hardware RNG) | Sampled from unpredictable physical entropy | Seeding CSPRNGs, high-assurance cryptographic keys |
| Quantum RNG (QRNG) | Derived from quantum-mechanical randomness (e.g. photon behavior) | Specialized security hardware, research |
Common Uses for Random Numbers
| Use Case | Typical Range | Notes |
|---|---|---|
| Dice roll simulation | 1–6 (or 1–20 for many-sided dice) | Single draw, duplicates allowed by design |
| Coin flip | 0–1 (heads/tails) | Binary random choice |
| Raffle / giveaway winner | 1 to total number of entries | Often uses "no duplicates" for multiple winners |
| Lottery number picks | Varies by game, e.g. 1–49 | Real lotteries use certified, audited RNGs |
| Statistical sampling | 1 to population size | Ensures unbiased selection from a dataset |
| Percentage-based decisions | 1–100 | Used in games, A/B testing, probability checks |
| Password/PIN character selection | Character-set index range | Must use a CSPRNG, not a general PRNG (see below) |
Security: When NOT to Use This Tool
Do not use this generator, or any general-purpose
Math.random()-based tool, to create passwords, PINs, API keys, encryption keys, session tokens, or anything where predictability would create a security risk. General PRNGs are optimized for speed and statistical distribution, not for resisting an attacker who is actively trying to predict future outputs from past ones — in some engine implementations, an attacker who observes enough outputs can reconstruct the internal state and predict subsequent values.
For anything security-sensitive, use a cryptographically secure pseudo-random number generator (CSPRNG) instead:
- In the browser: the Web Crypto API's
crypto.getRandomValues(). - In Node.js: the built-in
crypto.randomBytes()orcrypto.randomInt()functions. - In Python: the
secretsmodule (not the general-purposerandommodule). - For dedicated password generation: a reputable password manager's built-in generator, which uses a CSPRNG under the hood.
Worked Examples
Range: 1–6, Quantity: 1, Duplicates allowed → simulates one roll of a standard six-sided die.
Range: 1–250 (total entries), Quantity: 5, No duplicates enabled → draws 5 distinct winning entry numbers.
Range: 1–49, Quantity: 6, No duplicates + sort ascending → returns 6 unique numbers in increasing order, similar to many national lottery formats.
Range: 1–100, Quantity: 1, Decimal mode off → useful for simulating a probability check (e.g. "if the result is ≤ 20, event occurs").
Statistical Properties & Seeds
A well-built RNG should produce a uniform distribution — over a large number of draws, every value in the range should appear roughly the same number of times, with no value favored. Short sequences will naturally show some clustering or apparent "streaks" purely by chance; this is expected statistical variance, not a flaw. True randomness has no memory — the outcome of one draw never influences the next.
A seed is the starting input to a PRNG's algorithm. Because this tool re-seeds automatically using the system's current time and internal browser entropy on every page load, you get a fresh, unpredictable sequence each time you generate numbers, rather than a fixed repeating pattern.
Common Misconceptions
- "It repeated a number, so it's broken." Independent random draws can and do repeat — with duplicates allowed, this is mathematically expected, not a bug.
- "A number that hasn't appeared in a while is 'due.'" Known as the gambler's fallacy — each draw is independent and has no memory of past results.
- "Random means every outcome is unlikely." In a uniform distribution, every outcome is equally likely — none is more or less probable than any other.
- "Any random number generator is secure enough for passwords." Cryptographic security requires a CSPRNG specifically, not just statistical randomness — see the security section above.
Limitations of This Calculator
- Not cryptographically secure. Do not use output from this tool for passwords, tokens, or encryption keys.
- Range and quantity constraints. "No duplicates" mode requires the range to contain at least as many values as the requested quantity.
- Not certified for regulated gaming. Official lotteries and licensed gambling platforms require independently audited, certified RNGs that meet specific gaming-commission standards — this general-purpose tool is intended for informal, non-regulated use only.
- Decimal mode rounds to two places. For higher-precision decimal randomness, additional configuration would be required beyond this tool's scope.
Glossary
- PRNG (Pseudo-Random Number Generator)
- An algorithm that produces a statistically random-looking sequence of numbers from a deterministic formula and a starting seed.
- TRNG (True Random Number Generator)
- A generator that derives randomness from an unpredictable physical process rather than an algorithm.
- CSPRNG (Cryptographically Secure PRNG)
- A PRNG specifically designed so that its future outputs cannot be predicted even if past outputs are known; required for security-sensitive uses.
- Seed
- The starting value fed into a PRNG's algorithm; the same seed and algorithm always reproduce the same output sequence.
- Uniform Distribution
- A probability distribution in which every value in a range has an equal chance of being selected.
- Entropy
- A measure of unpredictability or randomness in a system; higher entropy sources produce harder-to-predict values.
- Mersenne Twister
- A widely used PRNG algorithm known for a very long period and good statistical properties, used in many programming languages' default random modules.
Frequently Asked Questions
Q: How does a random number generator work?
A: Most online generators use a pseudo-random number generator (PRNG) — a deterministic algorithm seeded by an unpredictable value like the system clock — to produce numbers that pass statistical randomness tests.
Q: What is the difference between true random and pseudo-random numbers?
A: True random numbers come from an unpredictable physical process and never repeat; pseudo-random numbers come from a deterministic algorithm and will repeat exactly if you reuse the same seed.
Q: Is this random number generator good enough for a lottery or raffle?
A: Yes for informal drawings and giveaways. Official, regulated lotteries require certified, independently audited RNGs to meet gaming-commission standards.
Q: Can I generate random numbers without repeats?
A: Yes, enable "no duplicates" mode — just make sure your range has at least as many possible values as the quantity you're requesting.
Q: Is Math.random() safe to use for passwords or security keys?
A: No. Use a cryptographically secure generator like the Web Crypto API's crypto.getRandomValues() for anything security-sensitive.
Q: Can a random number generator produce the same number twice in a row?
A: Yes, unless "no duplicates" is enabled — each draw is independent, so repeats are statistically normal.
Q: What is a seed in a random number generator?
A: A seed is the starting value that initializes a PRNG's algorithm; the same seed always reproduces the same sequence of numbers.
This tool is provided for general, informal, and educational use. It is not certified for regulated gambling, official lottery drawings, or any application requiring cryptographic security. For security-sensitive randomness, use a cryptographically secure random number generator as described above.