🎲 Random Number Generator

Generate secure random integers within custom minimum and maximum bounds instantly.

Generating random numbers, and what random actually means here

Computers are deterministic, so true randomness has to come from somewhere outside the arithmetic. Modern browsers collect entropy from hardware sources such as timing jitter and device noise, and expose it through crypto.getRandomValues. This generator uses that, not Math.random, which is fast, predictable and unsuitable for anything where the outcome matters.

Pseudorandom versus cryptographically secure

Two kinds of random
PropertyMath.random (PRNG)crypto.getRandomValues (CSPRNG)
Statistically uniformYesYes
Predictable from past outputsYes, given enough samplesNo
Reproducible from a seedYesNo
Suitable for games and simulationsYesYes
Suitable for prizes, keys, drawsNoYes

A pseudorandom generator starts from a seed and produces a deterministic sequence that merely looks random. Observe enough output and the internal state can be reconstructed, after which every future value is known. That is fine for shuffling a solitaire deck and unacceptable for picking a competition winner.

Modulo bias, the subtle bug

The obvious way to get a number from 1 to 10 is to take a random byte and use the remainder modulo 10. A byte has 256 values; 256 divided by 10 is 25 remainder 6, so the values 0 to 5 appear 26 times and 6 to 9 appear 25 times. The first six outcomes are 4% more likely than the rest.

The fix is rejection sampling: discard any value in the uneven tail and draw again. This generator does that, so every value in your chosen range is equally likely. Most quick implementations found online do not, which is invisible in casual use and shows up immediately in a large enough sample.

If you are generating numbers for anything consequential, check that the tool documents how it avoids modulo bias. A generator that cannot tell you is probably biased.

With or without repeats

Drawing with replacement means each draw is independent and values can repeat. Drawing without replacement removes each value as it is picked, which is what a lottery or a raffle does. The distinction matters: picking six numbers from 1 to 49 with replacement allows the same number twice, which is not how any real draw works.

Without replacement, the number of possible combinations is large. For 6 from 49 it is 49! / (6! × 43!) = 13,983,816, which the scientific calculator will confirm.

Why random sequences look wrong

People systematically expect randomness to be more evenly spread than it is. In 20 coin flips, a run of four or more identical results appears about half the time, yet it feels like a pattern. Asked to write a random sequence by hand, people alternate too often and avoid repeats, which makes human-generated sequences easy to distinguish from real ones.

The related error is the gambler's fallacy: believing that after five heads, tails is somehow due. Each flip is independent and the probability remains one half. A fair coin has no memory, and neither does this generator.

Common uses

A worked example

A prize draw with 340 entrants, picking three winners. Generate three integers from 1 to 340 without replacement. With replacement there would be a 1 − (339/340) × (338/340) = 0.87% chance of a duplicate across three draws, which sounds small but happens often enough across many draws to be a problem worth designing out.

Frequently Asked Questions (FAQs)

Is this truly random?

It uses your browser's cryptographically secure generator, which draws on hardware entropy rather than a deterministic algorithm. That is not philosophically true randomness, but it is unpredictable in any practical sense and is the same mechanism used for cryptographic keys.

What is modulo bias?

When a random range does not divide evenly into the generator's output range, some values come up slightly more often. Taking a byte modulo 10 makes the values 0 to 5 about 4% more likely. This generator uses rejection sampling to eliminate it.

Can I use this for a prize draw?

Yes. It uses a cryptographically secure source and corrects for modulo bias, which is what matters for fairness. For draws with legal or regulatory weight, record the process and the result at the time, and consider a witnessed or publicly verifiable method.

What is the difference between with and without replacement?

With replacement, every draw is independent and numbers can repeat. Without replacement, each number is removed once drawn, like a lottery or a raffle. Choose without replacement whenever duplicate results would be invalid.

Why do random numbers sometimes repeat?

Because independence means repeats are expected. Drawing ten numbers from 1 to 100 with replacement gives roughly a 37% chance of at least one duplicate. The absence of repeats would itself be evidence that the sequence is not random.

Does the computer send my numbers anywhere?

No. Generation happens entirely in your browser and nothing is transmitted or stored. The page continues to work with the network disconnected, which you can verify by going offline and reloading.