Random number generator

Generate unbiased random numbers, dice rolls and coin flips — securely, in your browser.

Result
Click generate to roll your numbers.

How a fair random number generator works

A random number generator (RNG) picks values from a range so that — over many draws — every number is equally likely. The catch is that most everyday RNGs cheat in two ways: they are predictable, and they are subtly biased. This tool fixes both. It draws from crypto.getRandomValues(), the browser’s cryptographically secure generator, and it removes the classic “modulo bias” using a technique called rejection sampling.

The math: why plain modulo is biased

Computers produce raw randomness as large integers — here, 32-bit values from 0 to 4,294,967,295. To squeeze one into a smaller range you might reach for the remainder operator: value % rangeSize. But unless the range divides 4,294,967,296 evenly, the lowest few outcomes get one extra chance each, making them slightly more common. The fix is to compute a cut-off and discard (reject) any raw value that lands in the leftover tail:

  • range = (max − min) + 1
  • limit = floor(2³² / range) × range
  • Draw a raw 32-bit value v; if v ≥ limit, throw it away and draw again.
  • Otherwise return min + (v % range) — now perfectly uniform.

For decimals the tool instead scales a uniform fraction across the span: min + fraction × (max − min), then rounds to your chosen number of places.

A worked example

Suppose you want one integer from 1 to 6 (a dice roll). The range is 6 − 1 + 1 = 6. The cut-off is floor(4,294,967,296 / 6) × 6 = 4,294,967,292, so only the top four raw values out of four billion are ever rejected. A draw of, say, 3,000,000,003 gives 1 + (3,000,000,003 % 6) = 1 + 3 = 4 — you rolled a 4. Every face has an exactly equal 1/6 ≈ 16.67% chance.

Options at a glance

OptionWhat it does
No duplicatesDraws without replacement, so every number is unique (like lottery balls).
Sort resultsOrders the output from lowest to highest instead of draw order.
DecimalsReturns fractional values rounded to 0–10 places of your choosing.
Dice / Coin presetsOne-click setups: 1–6 for a die, or 0/1 mapped to heads/tails.

Cryptographically secure

Powered by the Web Crypto API — not the weak, seedable Math.random() most pages use.

Bias-free

Rejection sampling guarantees every value in your range is equally likely.

Flexible

Any range, batch sizes up to a thousand, integers or decimals, unique or repeatable.

Privacy note: this generator has no server and no analytics on your input. Every number is produced on your own device and exists only in this browser tab until you copy or close it — ideal for prize draws, random sampling and anything you would rather keep private.

Frequently asked questions

Are these random numbers truly random?

They use crypto.getRandomValues(), the browser’s cryptographically secure random number generator (CSPRNG), not the predictable Math.random(). For each integer the tool also applies rejection sampling so every value in your range is equally likely, with no modulo bias. That is far stronger than ordinary pseudo-random output and is suitable for raffles, sampling and games.

What does “no duplicates” do?

When ticked, every number in the result is unique — like drawing distinct lottery balls. The tool draws without replacement, so once a value appears it cannot appear again. This only works if your range is at least as large as the count you ask for; otherwise there are not enough distinct values to fill the list and you will see a friendly error.

Can I generate decimals instead of whole numbers?

Yes. Switch the type to “Decimal” and choose how many decimal places you want (0–10). The tool generates a uniform random value across your min–max range and rounds it to that precision. Integer mode returns whole numbers only and is the default.

Why did I get a “range too small” error?

You asked for unique numbers but the span between min and max is smaller than the count requested. For example, asking for 10 unique numbers between 1 and 5 is impossible — there are only 5 distinct values. Either widen the range, lower the count, or untick “No duplicates”.

Is anything I generate sent to a server?

No. Every number is created locally in your browser and nothing is transmitted, logged or stored. Refresh or close the tab and the result is gone. That makes it safe for sensitive draws like prize winners or test samples.