Random Number Generator

Generate random numbers within a range. Supports multiple numbers with or without duplicates.

Source: National Lottery — Lotto

Konstantin Iakovlev

By Konstantin Iakovlev · Founder, Calks.uk

Last updated: · Methodology reviewed for 2026

Disclaimer

This calculator is for guidance only. Double-check any result you rely on. Everything is calculated in your browser; nothing you enter is sent to our servers.

How It Works

This tool generates random numbers within a range you specify. It uses a cryptographically secure pseudorandom number generator (CSPRNG), so the results are fair and unbiased, and you can ask for a single number or a set of several numbers, with or without repetition. Common uses include raffle draws, lottery number selection, random sampling for surveys, assigning people to random groups and settling decisions fairly. The generator can also produce dice rolls, coin flips and card draws with the correct probability distributions.

The difference between true random and pseudo-random matters more than most people expect. Math.random() in browsers relies on pseudo-random algorithms such as xorshift128+, which are fine for games, raffles and statistical sampling but become predictable if the seed is known. For anything cryptographic, crypto.getRandomValues() draws on entropy gathered by the operating system from sources such as mouse movements and thermal noise. Truly random numbers come from physical processes such as radioactive decay or quantum sources. ERNIE, the machine that picks Premium Bond winners, originally used valves and now uses semiconductors to produce roughly 50 million numbers a month.

Getting a fair result within a range is not quite as simple as multiplying Math.random() by N, adding 1 and rounding down. That naive approach gives a uniform distribution for most ranges, but for very large N it introduces a tiny modulo bias, because the underlying values do not divide evenly into the range. For ranges under 2^32 the bias is negligible. Where exact uniformity matters, the accepted method is rejection sampling: generate full 32-bit integers and discard any that fall above the largest multiple of the range, so every remaining value maps to an outcome with equal probability. The same principle sits behind UK jury selection, which has been computerised since 1974, when it replaced the old manual property-qualified system.

Lottery players are probably the largest single group of users, and the odds are worth knowing before you pick. National Lottery Lotto draws 6 balls from 59, giving a 1 in 45,057,474 chance of the jackpot and 1 in 9.3 of any prize. EuroMillions (5 from 50 plus 2 from 12) has jackpot odds of 1 in 139,838,160, and Set for Life (5 from 47 plus 1 from 10) sits at 1 in 15,339,390 for the top prize. A random pick does not improve those odds, but it does avoid the clusters humans favour: birthdays keep picks between 1 and 31, and many people choose 7, 11, 13 or other 'lucky' numbers. If you do win with a random set, you are less likely to have to share the prize. Lottery winnings are tax-free in the UK because they count as gambling, although any interest earned on the winnings is taxable.

Security work is where the choice of generator stops being optional. Use crypto.getRandomValues() rather than Math.random for password generators (each character drawn from a pool of 70-94 characters), 2FA backup codes, session tokens, CSRF tokens, encryption nonces, UUID v4 generation and salts for password hashing. The UK ICO and NCSC require a CSPRNG for systems that handle personal data. All modern browsers have supported the secure API since 2014, so there is no compatibility excuse for using the weaker one. Math.random is weak for security purposes because its outputs can be reverse-engineered.

Beyond lotteries and passwords, randomness underpins a surprising amount of everyday technology. Statistical sampling for polling and market research relies on random selection to minimise bias. Computer games use it for enemy AI behaviour and loot drops. Music shuffle is rarely truly random: Spotify uses a weighted shuffle that spaces out tracks by the same artist. A/B testing assigns each visitor at random to variant A or B, and drug trials depend on double-blind randomisation for valid results. Cryptocurrency mining is in effect a lottery for finding a valid block hash, and the UK MoD's CHACR has published research on military uses of high-quality random number generators.

Example: Generating lottery numbers

  1. Range: 1 to 59 (UK Lotto)
  2. Quantity: 6 numbers, no repeats
  3. Result: e.g. 7, 14, 22, 35, 41, 53
  4. Each draw is independent and equally likely

Source: National Lottery — Lotto

Frequently Asked Questions

Is Math.random() safe enough for a raffle or prize draw?
For a raffle, a classroom draw or statistical sampling, yes. Math.random() uses a pseudo-random algorithm such as xorshift128+, which produces a fair spread of results for those purposes. Its weakness is that the sequence is predictable if the seed is known, which only matters when someone has an incentive to attack it. This generator uses a CSPRNG instead, so the same tool is safe for both a charity raffle and a security token.
Does picking lottery numbers at random improve my chances of winning?
No. The odds are fixed by the game: 1 in 45,057,474 for the Lotto jackpot (6 balls from 59), 1 in 139,838,160 for EuroMillions and 1 in 15,339,390 for the Set for Life top prize. What a random pick does change is how many people you are likely to share with. Human choices cluster on birthdays (1 to 31) and favourites like 7, 11 and 13, so a random line is less likely to be duplicated by another ticket.
Why must password generators use crypto.getRandomValues() instead of Math.random?
Because Math.random outputs can be reverse-engineered, which means a password built from them could be reconstructed. crypto.getRandomValues() draws on operating-system entropy and is what the UK ICO and NCSC expect for systems handling personal data. It has been supported by all modern browsers since 2014. The same rule applies to 2FA backup codes, session and CSRF tokens, encryption nonces, UUID v4 values and password salts.
How does the generator avoid bias when picking from a range?
The simple method of multiplying a random fraction by the range size and rounding down is slightly biased for very large ranges, because the generator's values do not divide evenly into the range. For anything under 2^32 the effect is negligible, but a careful implementation uses rejection sampling: it generates full 32-bit integers and throws away any above the largest multiple of the range, so each remaining value has an equal chance.
Can I generate several numbers without any repeats?
Yes. Set the range, say 1 to 59 for a UK Lotto line, ask for 6 numbers and switch off repeats. The tool then draws each number from the values not yet used, so you get a set such as 7, 14, 22, 35, 41, 53. With repeats allowed, each draw is independent and any value can appear more than once, which is what you want for dice rolls or coin flips.