Skip to the tool
DevToolBench

Random Number Generator

Pick numbers in a range, drawn without modulo bias.

Every number is drawn in this tab by your browser’s cryptographic generator, with the biased remainder thrown away rather than kept. Nothing is sent anywhere and no draw is recorded, so copy the result before you close the page.

1–1000
0–6
Numbers drawn
0
Possible results
Odds on the first draw
Repeats
Allowed

Everything runs in your browser. Nothing you type is sent to a server.

Found a bug in this tool? Report it.

Share this tool

What this tool does

This random number generator draws whole numbers or decimals between any two values you choose, one at a time or up to a thousand at once, with or without repeats. Both ends are inclusive: ask for 1 to 6 and you can get 1 or 6, which is not true of every generator you will find.

The numbers come from crypto.getRandomValues in your own browser. Nothing is requested from a server, nothing is logged, and the draw cannot be replayed — including by us.

Pseudorandom, cryptographic, and the difference that matters

Math.random is a pseudorandom generator: a small amount of internal state, a fast arithmetic step, and a stream of numbers that pass the usual statistical tests. It is perfect for jitter, for shuffling a demo playlist, for a particle effect. It is also completely predictable to anyone who recovers that state, and browsers make no promise about how it is seeded.

crypto.getRandomValues is the other kind. It draws from the operating system's entropy pool through a construction meant to survive an adversary who has seen a great deal of previous output. The cost is negligible at this scale, and the difference only shows up when someone has a reason to guess your next number — a prize, a slot in a queue, a token. Since that is exactly the case where a random number tool gets used, this page uses the strong one for everything.

Why the remainder gets thrown away

The naive way to get a number from 1 to 6 out of a 32-bit draw is to take the remainder after dividing by 6. It looks fair and it is not. 4,294,967,296 divided by 6 leaves 4 over, so four of the six outcomes appear one extra time in the mapping and come up slightly more often.

The fix costs four lines: work out where the last complete cycle ends, discard any draw beyond it, and go again. In a range of 6 the discarded slice is four values out of four billion, so in practice you almost never draw twice — but the result is exactly uniform rather than nearly uniform, and "nearly" is not a property you want to explain afterwards.

Decimals go through the same path. Asking for two decimal places between 0 and 1 is treated as a draw among the 101 whole numbers from 0 to 100, which is then divided. No floating point addition happens anywhere near the draw, so 0.30 is exactly as likely as 0.29.

Repeats, and the birthday problem

With repeats allowed, every number is an independent draw and duplicates are normal — expected, even. Pull ten numbers from 1 to 100 and the chance that at least two match is about 37%, which surprises people every time. It is the same arithmetic that makes two people in a room of 23 share a birthday more often than not.

Switching repeats off changes the experiment. The draw becomes a sample without replacement, implemented as a partial Fisher–Yates shuffle over the range: each pick swaps a used slot out of the pool, so nothing can come back. Only the positions actually touched are stored, which is why you can ask for ten distinct numbers between 1 and a billion without the page allocating a billion of anything.

No seed, on purpose

There is no seed field here. A seeded generator is reproducible by design, and reproducibility is the opposite of what a draw with something at stake needs — whoever knows the seed can replay the winner. Seeds belong in your test suite, where a fixed sequence is the point, not on a page whose whole job is to be unguessable.

Need something other than numbers? The password generator uses the same rejection sampling over character sets, and the UUID generator covers identifiers.

Frequently asked questions

Are these numbers really random?

They come from crypto.getRandomValues, the browser's cryptographically secure generator, which is seeded from entropy the operating system collects and is designed so that seeing past output tells you nothing about future output. That is a much stronger promise than Math.random makes. For a prize draw, a shuffle or a sampling decision it is more than enough; for anything with legal weight, use a process someone can audit rather than a web page.

What is modulo bias?

The flaw in the obvious way to squeeze a big random number into a small range. A 32-bit draw has 4,294,967,296 possible values, and if you ask for a number from 1 to 6 by taking the remainder, four of the six faces get one extra chance because 4,294,967,296 is not a multiple of 6. The gap is tiny per draw and measurable over a few million. This page throws away the leftover values instead and draws again, so every result has exactly the same chance.

Does turning off repeats change the odds?

Yes, on every draw after the first. Ten independent numbers from 1 to 100 have a better than even chance of containing a duplicate — the birthday problem again. Ask for ten with no repeats and the second number is chosen from 99, the third from 98, and so on. That is a different experiment: it is a sample without replacement, and it is the right one for raffles and wrong one for dice.

Can I set a seed to reproduce a draw?

Not here, and that is deliberate. A seed makes a sequence repeatable, which is exactly what you want for a test fixture and exactly what you do not want for a draw with a winner in it — anyone who learns the seed can replay the result, and a page that offers one invites people to use it where it hurts. If you need reproducibility, use a seeded PRNG in your own code where the seed is under your control.

How many numbers can I generate at once?

Up to 1000 per draw, in a range as wide as 4,294,967,296 possible results and as fine as six decimal places. Decimals are handled by scaling the range to whole numbers before the draw, so asking for two decimal places between 0 and 1 is a fair draw among 101 values rather than a rounded float.

Related tools

Updated