Random Number Generator
Set a minimum and a maximum, choose how many numbers you need, decide whether duplicates are
allowed, and optionally sort the output. You can generate whole numbers or decimals,
copy the result in one click, or download it as a text file. Everything runs locally in your
browser using JavaScript's built-in Math.random() — a standard pseudo-random number
generator, not a cryptographic one. Great for mock data, sampling, classroom
examples and casual draws. Not suitable for cryptographic keys, security tokens or high-stakes
gambling.
Decimals are drawn from a continuous range, so “unique values only” does not apply.
Your numbers
How to use this random number generator
- Enter the minimum and maximum values that define your range — both ends are included.
- Set how many numbers you want (1 to 10,000).
- Pick the number type: whole numbers, or decimals with 1–6 decimal places.
- Choose whether duplicates are allowed. Turn them off for raffle-style “pick 6 unique numbers” draws.
- Optionally pick a sort order: as generated, low-to-high, or high-to-low.
- Click Generate Random Numbers.
- Use Copy to put a comma-separated list on your clipboard, or Download to save one number per line as a
.txtfile.
The results panel stays hidden until you generate, then remains visible until you generate again. If a rule is broken, a red message appears above the button explaining exactly what to fix. Quick presets at the top fill in every field for common jobs like dice rolls or lottery picks.
What is a random number generator?
A random number generator (RNG) is any process that produces values with no predictable pattern. In computing there are three broad families, and it matters a great deal which one you are using:
- TRNG — a true random number generator measures a physical source such as atmospheric noise, radioactive decay or thermal jitter. Slow, expensive, but genuinely non-deterministic.
- PRNG — a pseudo-random number generator is a deterministic algorithm
seeded with an initial state. Given the same seed it produces the same sequence. Fast and
statistically excellent for everyday work.
Math.random()is one of these. - CSPRNG — a cryptographically secure pseudo-random generator is designed
so that observing past output gives you no practical advantage in predicting future output.
Browsers expose one through
crypto.getRandomValues().
This tool uses the second kind. It is the right choice for mock data, sampling and casual draws, and the wrong choice for anything an attacker would profit from guessing.
How this tool generates its numbers
The generator is deliberately simple and readable, so you can reason about what it does:
-
Whole numbers (duplicates allowed). Each value is
Math.floor(Math.random() × (max − min + 1)) + min, which maps the half-open interval[0, 1)onto your inclusive range[min, max]. -
Whole numbers (duplicates disallowed). Two strategies are used depending on the
shape of the request. When the sample is small relative to the range (count ≤ half the range),
the tool draws values and rejects repeats using a
Set— fast, and memory use scales with the sample, not the range. When the sample is a large fraction of the range, it performs a partial Fisher–Yates shuffle over the pool and takes the first count entries. Both strategies yield a uniform sample drawn without replacement. -
Decimals. Each value is
min + Math.random() × (max − min), then rounded to your chosen number of decimal places. The distribution is uniform over the interval. - Sorting is applied after generation and never changes which values were drawn — it only changes the order you see them in.
Is the distribution uniform?
Yes, to any precision that matters here. Math.random() produces values of the form
k / 252, i.e. 252 equally likely outcomes. Scaling by a range
of n means each bucket receives either ⌊252/n⌋ or
⌈252/n⌉ outcomes, so the relative bias is on the order of
n / 252 — roughly one part in a quadrillion for a range of a few
thousand. It is far below anything observable in practice.
What you should avoid in your own code: the classic
Math.floor(Math.random() * 10) % n pattern, or reducing a large random integer with
%. Those genuinely do introduce modulo bias. This tool does not use them.
Duplicates: with and without replacement
This is the single setting people get wrong most often, so it is worth being precise about it.
| Setting | What happens | Use it for |
|---|---|---|
| Allow duplicates = Yes | Each number is drawn independently. The same value can — and will — appear more than once. This is sampling with replacement. | Dice rolls, repeated trials, simulating independent events, generating filler data. |
| Allow duplicates = No | The tool draws without replacement, so every value in the output is distinct. If you ask for more numbers than the range contains, it refuses rather than returning a short list. | Lottery-style picks, raffle winners, sampling rows from a list, choosing distinct seats or slots. |
How often do duplicates appear by chance?
When duplicates are allowed, the expected number of collisions in k draws from a range of
n values is approximately k(k − 1) / 2n. This is the birthday problem in
disguise, and it surprises people constantly:
- 10 draws from 1–100 → about 0.45 duplicate pairs expected.
- 10 draws from 1–10 → about 4.5 duplicate pairs expected; repeats are the norm, not the exception.
- 23 draws from 1–365 → better than a 50% chance that two values match.
So if you generated 10 numbers between 1 and 10 and saw repeats, that is not a bug — it is the mathematics working exactly as intended. Switch duplicates off if you need distinct values.
Randomness quality: what Math.random() really is
Math.random() is specified by the ECMAScript standard only as returning a Number in
[0, 1) chosen “with approximately uniform distribution”, using an
implementation-dependent algorithm. The standard deliberately does not mandate a
particular generator, so the exact algorithm differs between browsers.
In practice, modern engines (V8 in Chrome and Edge, SpiderMonkey in Firefox) use fast xorshift-family generators with a large internal state. They pass statistical randomness test suites comfortably for everyday purposes. What they are not designed to resist is an adversary: the internal state can, in principle, be recovered from enough observed output, and then every future value is predictable.
Math.random() |
crypto.getRandomValues() |
|
|---|---|---|
| Type | PRNG | CSPRNG |
| Source of entropy | Algorithmic, internally seeded | Operating-system entropy pool |
| Predictable if state leaks? | Yes | No, by design |
| Speed | Very fast | Fast, but slower per call |
| Typical output | Float in [0, 1) |
Integer typed arrays |
| Safe for passwords, keys, tokens? | No | Yes |
| Fine for mock data & casual draws? | Yes | Yes (overkill) |
This tool does not use crypto.getRandomValues(). If you need
cryptographic randomness, call it directly in your own code — the browser API is
crypto.getRandomValues(new Uint32Array(1)), and it caps at 65,536 bytes per call.
Common uses and the settings for them
| Task | Min | Max | Count | Duplicates | Sort |
|---|---|---|---|---|---|
| Roll a single six-sided die | 1 | 6 | 1 | Yes | — |
| Roll 5 dice at once | 1 | 6 | 5 | Yes | Low → high |
| Coin flip (0 = tails, 1 = heads) | 0 | 1 | 1 | Yes | — |
| Lottery-style pick of 6 from 1–49 | 1 | 49 | 6 | No | Low → high |
| Random sample of 10 rows from 1–1000 | 1 | 1000 | 10 | No | Low → high |
| Placeholder integers for a spreadsheet | 1 | 100 | 500 | Yes | — |
| Simulated test scores | 0 | 100 | 30 | Yes | High → low |
| Random coordinates or measurements | -180 | 180 | 50 | Yes | — |
For a random sample of rows from a real list, generate unique indices in the range
1…N where N is the number of rows, then pick those rows in the generated
order (choose “As generated” rather than sorted, so the sample itself is in random order).
Limitations — and when not to use this tool
- Not cryptographically secure. Never use this output for passwords, encryption keys, session tokens, nonces, salt values, CSRF tokens, or anything a security decision depends on.
- Not for real-money gambling or official lotteries. Regulated draws require certified, auditable hardware and published verification procedures. This page has none of that.
- No seed input, no reproducibility. There is no way to reproduce a previous run, and no audit trail. Each click produces a fresh sequence you cannot recover.
- No shuffling of your own list. This tool generates numbers, not permutations of your data. Use a dedicated list shuffler for that.
- No weighted or non-uniform distributions. Every value in the range is equally likely. There is no “bell curve”, no weighting, and no exclusion list beyond switching duplicates off.
- Not a statistical test suite. The tool does not run chi-square, Kolmogorov–Smirnov or any other randomness test on its output. It just generates values.
- Decimals are rounded. A value rounded to 2 decimal places can land exactly on your maximum. Treat the range as inclusive at both ends, even in decimal mode.
Validation rules and error messages
The generator refuses to run in five situations, and tells you which one applies:
| Message | Cause and fix |
|---|---|
| Minimum and maximum must be numbers. | A field is empty or contains something that is not a number. Enter digits only. |
| Minimum value must not be greater than the maximum value. | Your range is inverted. Swap the two values. Equal min and max is allowed — it just produces a constant result. |
| Values must be between −1,000,000,000 and 1,000,000,000. | The range endpoints are outside the supported envelope. Keep them inside ±1 billion. |
| How many numbers must be a whole number between 1 and 10,000. | The count is zero, negative, fractional, or above the per-run cap. |
| Not enough unique values in range. | You asked for more distinct numbers than the range contains. Widen the range, lower the count, or allow duplicates. |
In whole-number mode, a fractional minimum is rounded up and a fractional maximum is rounded down, so the range always describes actual whole numbers.
Frequently asked questions
How random are these numbers?
The tool uses Math.random(), JavaScript's standard pseudo-random generator. For everyday uses — mock data, sampling, casual draws — the output is effectively random and passes statistical tests comfortably. It is not cryptographically secure, so don't use it for passwords, keys or tokens, where a predictable sequence would matter.
Can I generate unique numbers for a draw or lottery?
Yes, for low-stakes draws. Set your range (say 1–49), set the count to however many numbers you want, and set Allow Duplicates to No. Be aware this uses a non-cryptographic PRNG — for anything with real money or real stakes attached, use an officially verifiable draw mechanism instead.
What does "Allow duplicates: No" actually do?
It draws without replacement, so every value in the output is distinct. For small samples it uses rejection sampling with a Set; for samples that cover a large fraction of the range it performs a partial Fisher–Yates shuffle. If you ask for more unique numbers than the range can supply, the tool shows an error instead of returning a short list.
Why did I get the same number twice?
Because duplicates were allowed, and repeats are far more likely than intuition suggests. In 10 draws from a range of 10 values you should expect about 4–5 duplicate pairs. See the birthday-problem figures above. Turn duplicates off if you need distinct values.
Are the minimum and maximum included?
Yes. Both endpoints are part of the range. For example, with min 1 and max 6 you can roll a 1 and you can roll a 6, each with probability 1/6.
Can I generate decimals?
Yes. Set Number Type to Decimals and choose 1–6 decimal places. Values are drawn uniformly between your minimum and maximum and then rounded. Because decimals are effectively continuous, the “unique values only” option is disabled in this mode.
Can I reproduce a previous run?
No. There is no seed field, so every run is different and cannot be replayed. If you need reproducibility — for a published experiment, for example — you need a seeded PRNG such as a small xorshift or a Mersenne Twister implementation, which is outside the scope of this tool.
Why does the tool cap the count at 10,000?
Rendering tens of thousands of individual numbers makes the tab sluggish and the page hard to read. The cap keeps the tool responsive. You can still click Generate as many times as you like — there is no usage limit, no rate limit and no account required.
Does sorting the output affect the randomness?
No. Sorting happens after the numbers are drawn and only changes the order they are displayed in. The set of values is exactly the same either way.
Is my input sent anywhere?
No. Everything runs in your browser with JavaScript. Your range, count and settings never leave the page, and the generated numbers are not stored anywhere.
Glossary
- PRNG
- Pseudo-random number generator. A deterministic algorithm that produces a sequence which looks random. Reproducible if you know the seed.
- CSPRNG
- Cryptographically secure pseudo-random number generator. A PRNG whose output is unpredictable even to an attacker who has seen previous output.
- TRNG
- True random number generator. Derives randomness from a physical, non-deterministic source.
- Seed
- The initial value that determines a PRNG's entire output sequence. This tool exposes no seed, so sequences cannot be replayed.
- With replacement
- Sampling where a value can be drawn more than once. Equivalent to “Allow duplicates = Yes”.
- Without replacement
- Sampling where a value is removed from the pool once drawn, guaranteeing distinct results. Equivalent to “Allow duplicates = No”.
- Uniform distribution
- Every value in the range has the same probability of being chosen. This tool is uniform; it has no weighting.
- Modulo bias
- A subtle skew introduced when a random value is reduced with the
%operator against a range that does not divide the generator's output space evenly. Avoided by this tool. - Fisher–Yates shuffle
- A classic algorithm for producing an unbiased random permutation. Used here in partial form for drawing large unique samples.
- Birthday problem
- The counter-intuitive fact that collisions become likely far sooner than the size of the range suggests — around √n draws for a range of n.
Privacy
Everything you enter into this tool stays inside your browser tab. There is no upload, no server round-trip, and no logging of your inputs or the numbers generated. The page is plain HTML, CSS and JavaScript served from Blogger — the only network request is the initial page load. Clipboard writes and file downloads happen entirely on your device.
Last reviewed: October 2026