While generating a random number from a given range, we must ensure that all numbers have an equal likelihood of being generated. For example, when generating a random number between
We can think of a coin as a random number generator. Flipping a coin only has two outcomes, heads or tails, each with a probability of
To use a coin to generate a number between
Numbers in our everyday life are usually in the decimal or base-10 system because each digit can have one of ten values (
We can use at least three digits to represent all the numbers in the range
Base-10 | Base-2 |
0 | 000 |
1 | 001 |
2 | 010 |
3 | 011 |
4 | 100 |
5 | 101 |
6 | 110 |
7 | 111 |
Note: Click here to learn how to convert decimal and binary values.
As we can see, a base-10 number can be represented as a sequence of 1s and 0s. If we have to generate a base-10 number between
Luckily, we have a random binary generator, our coin!
If we flip the coin three times and note the results as
The simulation below demonstrates the process:
As we stated before, any number between
Three consecutive coin flips have the following possible outcomes. An 'H' represents heads while a 'T' represents tails.
Possible results | Base-2 | Base-10 |
HHH | 000 | 0 |
HHT | 001 | 1 |
HTH | 010 | 2 |
HTT | 011 | 3 |
THH | 100 | 4 |
THT | 101 | 5 |
TTH | 110 | 6 |
TTT | 111 | 7 |
Note: We treat a heads as 0 and a tails as 1.
Any single outcome has a 1 in 8 chance of occurring. Hence each number is equally likely.
We can use a coin can to generate a random number between any range
Free Resources