Calculators
4 digit random number generator
Select Generate numbers for one random 4-digit number between 1000 and 9999. All 9,000 of them have the same 1 in 9,000 chance, including 1000 and 9999 themselves. For several at once, raise How many numbers, and select No repeats so that no number appears twice. The number is drawn in your browser.
How to get a random 4 digit number
The form opens on the 4-digit range with a single number, so the first click already gives a result. The steps below name the labels exactly as they appear on the page.
- Leave Minimum value at 1000, Maximum value at 9999 and How many numbers at 1, with Number type on Integers.
- Select Generate numbers. The 4-digit number appears in the box under Your numbers.
- Select Generate again for another one. Every draw starts fresh and ignores earlier results.
- Select Copy results to paste the number elsewhere, or Download .txt to save random-numbers.txt, one number per line.
Editing any field, including No repeats, clears the shown result until you generate again. Reset returns the form to 1000 to 9999 with one number and an empty box. For a very long list, Cancel stops the run before it finishes.
Why the range starts at 1000
A whole number has 4 digits when it is at least 1000 and at most 9999, so this page draws from those 9,000 numbers. In ordinary writing a number does not start with 0: 0427 is the 3-digit number 427.
Codes are different. A PIN or a door code can start with 0, so there are 10,000 of them, from 0000 to 9999. Some generators count those 10,000 when they say 4 digits.
This generator prints plain numbers and never adds leading zeros. Set Minimum value to 0 and it draws from all 10,000 values, but a result such as 42 appears as 42, not 0042, and 1 result in 10 has fewer than 4 digits. For codes that always show 4 digits, use the password generator below with only Numbers selected and Length set to 4.
The chance of each 4 digit number
Each number from 1000 to 9999 has a 1 in 9,000 chance on every draw, about 0.011%. The first digit is 1 to 9 with equal odds of 1 in 9, because each first digit leads 1,000 numbers. The last digit is 0 to 9 with odds of 1 in 10, so half the results are even.
In one check in Chrome, 1,000,000 draws through this page gave each number between 73 and 149 times, against an expected 111.1. Each first digit came up between 110,750 and 111,734 times, against 111,111.
Equal odds do not mean every number turns up in 9,000 draws. A given number such as 2024 appears at least once in only 63.2% of runs of 9,000 draws, and it takes 6,238 draws for that chance to pass one half.
How the generator avoids bias
The generator reads random bytes from Web Crypto, the browser's cryptographic random source, and uses rejection sampling. The range has 9,000 values, which need 14 bits. It reads two bytes and keeps the lowest 6 bits of the first and all 8 of the second, a value from 0 to 16,383. Values 0 to 8,999 become 1000 to 9999, and anything higher is thrown away before two new bytes are read.
About 55% of pairs are kept, so a number costs 3.64 bytes on average. The quick method of taking two bytes modulo 9,000 would be unfair: two bytes have 65,536 values, which is 7 full rounds of 9,000 plus 2,536 left over. So 1000 to 3535 would come up 8 times in 65,536 and the rest only 7 times, which makes the low numbers about 14% more likely. With rejection, every number keeps exactly 4 of the 65,536 values.
Repeats in a list of 4 digit numbers
Raise How many numbers above 1 for a list, one number per line. With repeats allowed, each line is a fresh, independent draw from all 9,000 numbers, so the same number can show up twice. A repeat comes sooner than most people expect:
| Numbers drawn | Chance of at least one repeat |
|---|---|
| 10 | 0.5% |
| 20 | 2.1% |
| 50 | 12.7% |
| 100 | 42.4% |
| 112 | 50.0% |
| 200 | 89.2% |
| 300 | 99.4% |
Each figure is 1 minus the chance that all numbers differ. For 2 numbers it is simply 1 in 9,000, about 0.011%. This is the birthday problem with 9,000 days instead of 365.
From 112 numbers on, a repeat is more likely than not, even though the list covers barely more than 1% of the range. For ticket numbers, raffle entries or codes that must all differ, select No repeats.
No repeats and repeated digits
With No repeats selected, the generator draws without replacement: a number it picks leaves the pool, and the next pick is even across the numbers left. How many numbers can then be at most 9000. At 9001 the page shows an error beside How many numbers and generates nothing. A count of 9000 lists every 4-digit number once, in random order.
No repeats works on whole numbers within one list. It does not stop a digit from repeating inside a number, so 1123 or 7777 can come up. Only 4,536 of the 9,000 numbers, 50.4%, have four different digits, so about half of all draws contain a repeated digit. The tool has no setting that removes them.
Each Generate starts a new list, which can repeat numbers from the list before. To keep numbers apart across lists, draw them all in one list.
Limits
The page draws digits only. It cannot mix letters into a code, spin a wheel or work out a lucky number from a date of birth. It keeps no history, so it cannot stop a number from coming back in a later list, and the result is cleared when you leave the page. It also keeps no record that could prove to someone else that a draw was fair.
The tool sets no cap on How many numbers. With repeats allowed, a list can be longer than 9,000. Above 10,000 numbers the box shows the first 10,000 to keep the page responsive, while Copy results and Download .txt include every number. Very large lists are limited by the browser's memory.
The page needs JavaScript and Web Crypto. Without them it shows a message instead of numbers.
Questions
Can you give me a 4-digit random number?
Yes. This page opens with Minimum value 1000, Maximum value 9999 and How many numbers 1, so selecting Generate numbers gives one right away. Select Generate again for another; each of the 9,000 numbers has the same chance every time. Two draws in a row can match, with a chance of 1 in 9,000.
What are some four-digit numbers?
Every whole number from 1000 to 9999 has four digits, 9,000 in all. For a sample, set How many numbers to 20 and select No repeats. For the full list, set it to 9000 with No repeats: every 4-digit number appears once, in random order, ready to copy or download.
Can I use this for a 4-digit PIN?
The numbers come from Web Crypto and are drawn in your browser, and the page keeps no history. The range 1000 to 9999 leaves out the 1,000 PINs that start with 0. For all 10,000 PINs from 0000 to 9999, use the password generator with only Numbers selected and Length 4.
What is the lucky number for 4 digits?
This generator has none. Every number from 1000 to 9999 has the same 1 in 9,000 chance, and the page asks for no date of birth or name, so it cannot work out a personal lucky number. In the check of 1,000,000 draws, the most frequent number came up 149 times against an expected 111.
How do I get 4 digit numbers with no repeats?
Select No repeats, set How many numbers to the count you need, up to 9000, and select Generate numbers. No number then appears twice in that list. Digits inside one number can still repeat, as in 5005, and a new list from Generate again can reuse numbers from the last one.
Related tools
- Generate a random password: with only Numbers selected and Length 4, it gives codes from 0000 to 9999 with leading zeros.
- Shuffle a list of lines: put a list of existing numbers or names in random order.
- Convert a number to another base: write a 4-digit number in binary, hex or another base.