Random Number Generator

Generate a uniformly selected random integer.

Reset

Understanding random numbers

A random draw feels simple — pick a number, any number — but fairness is harder than it looks. Ask a person to "pick a random number between 1 and 100" and they will favour 7, 37 and 73, avoid round numbers, and almost never say 1 or 100. Ask a group to draw a name from a hat and someone will wonder whether the slips were really shuffled.

Formula and method

N = b − a + 1
P = 1 ÷ N

The generator picks uniformly from the inclusive range. If the minimum is a and the maximum is b, the count of possible values is: and the probability of any one particular value is: Every value in the range has exactly this probability, and no value is favoured. The result is an integer: a draw between 1 and 100 never returns 37.5. Each generation is independent — the generator does not remember earlier results, so a value that just came up is exactly as likely to come up again as any other value. For a fair draw, the range is the whole story. If you want to pick one of 50 raffle tickets numbered 1 to 50, set the minimum to 1 and the maximum to 50: each ticket then has a 1-in-50 (2%) chance. If instead you draw from 1 to 100 for 50 tickets, half the numbers would belong to no ticket at all, and the draw would be meaningless. Match the range to the items.

Worked example

Example 1 — One ticket in fifty: what are the odds? A raffle has tickets numbered 1 to 50. You hold ticket 7. Possible values: 50 − 1 + 1 = 50 Probability your ticket is drawn: 1 ÷ 50 = 0.02, or 2% The average (expected) value of a draw from 1 to 50 is (1 + 50) ÷ 2 = 25.5 — the middle of the range, not a value the generator is more likely to produce. Every value from 1 to 50 is equally likely; 25.5 is simply the centre. A 2% chance means that if the raffle ran 50 times with fresh draws, your ticket would win about once on average — sometimes more, sometimes not at all.