Calculators

Random number generator 1 to 4

This page draws 1, 2, 3 or 4, and each number has an exact 25% chance every time. Use it in place of a four-sided die, to choose one of four options, or to put four players in a random order with No repeats. The draw happens in your browser.

Settings

Choose your range and how many numbers to generate.

Random number options

Use whole numbers, such as -25. No commas or exponents. For values like 2.50, switch Number type to Decimals.

Decimal places applies in Decimals mode. Endpoints must fit the chosen precision; they are never rounded.

Each value appears at most once in this batch.

Choose your options, then generate numbers.

Your numbers

Your results will appear here, one number per line.

Both endpoints are included in the possible values. Decimals are sampled at your chosen step: 2 decimal places means steps of 0.01.

No repeats needs enough values in the range. With repeats allowed, a value can appear more than once.

Getting a number from 1 to 4

The page loads with Minimum value 1, Maximum value 4 and How many numbers 1. Number type is Integers, so the result is always one of the four whole numbers.

  1. Select Generate numbers. One number from 1 to 4 appears in the box under Your numbers.
  2. For the next roll, select Generate again. Every roll is independent, so the same number can come up twice in a row.
  3. To keep a result, select Copy results, or select Download .txt for a file called random-numbers.txt.

Editing a field empties the result box until you generate again. Reset restores 1 to 4 with one number. If you need several rolls at once, type the count into How many numbers instead of clicking many times: a count of 10 gives ten rolls, one per line, which you can copy together.

A 1 in 4 chance

Each of the four numbers comes up with a chance of 1 in 4 on every draw. As a fraction that is 1/4, as a decimal 0.25 and as a percentage 25%. Two numbers together, such as 1 or 2, cover half of all draws, and three of them cover 75%.

The chance does not change with history. After three 4s in a row, the next draw is still 4 one time in four. In a check of 1,000,000 draws through the real engine, each number came up between 249,558 and 250,447 times against an expected 250,000, and 24.97% of draws repeated the draw before.

A 1 in 4 event is less rare than it sounds. Across five draws, a given number fails to appear only 23.7% of the time, and over ten draws only 5.6%. On average it takes 8.3 draws before all four numbers have appeared at least once.

Why four is the easiest range to make fair

The generator takes random bytes from Web Crypto, the browser's cryptographic random source. Four values fit exactly into 2 bits, because 4 is a power of two. The generator keeps the lowest 2 bits of a byte, a value from 0 to 3, and adds 1.

No value is ever thrown away. Each number owns exactly 64 of the 256 possible bytes, and every byte produces a result, so one number costs exactly one byte. Ranges of 3, 5 or 6 values are different: some byte values do not map evenly, and the generator has to reject them and read again.

The same code handles every range, so the 1 to 4 page uses the rejection method too; it simply never triggers here. The shortcut of dividing a byte by 4 and keeping the remainder would also be fair for this range, since 256 is exactly 64 fours. For most other ranges that shortcut is biased.

Four options, four-sided dice and quizzes

A common use is a choice among four things. Number the options first, then draw: each option gets a 25% chance. For a quiz with answers A, B, C and D, read 1 as A, 2 as B, 3 as C and 4 as D to pick a random answer letter.

As a replacement for a four-sided die, the d4 of tabletop games, one draw is one roll. For several dice, set How many numbers to the number of dice and add the results yourself; the page lists each roll and does not add them.

Four players or four teams can get a playing order with No repeats and a count of 4. There are 24 possible orders, each with a chance of 1 in 24, about 4.2%. In 60,000 such lists from the engine, each of the 24 orders appeared between 2,387 and 2,570 times, against an expected 2,500.

Repeats in a short list

With repeats allowed, a list of numbers from 1 to 4 repeats a number sooner than most people guess. Two draws match 25% of the time. Three draws contain a repeat 62.5% of the time, and four draws contain one 90.6% of the time. Only 9.4% of four-draw lists hold each number once.

Each figure is 1 minus the chance that all draws differ. For four draws that chance is 4 × 3 × 2 × 1 divided by 4 × 4 × 4 × 4, which is 24 in 256. This is the birthday problem with only four days in the year.

So when every number must appear once, select No repeats rather than drawing until the list looks right. With No repeats on, How many numbers can be at most 4. A count of 5 gives an error beside How many numbers and no result, because the range holds only four values.

Limits

Results appear as plain numbers. There is no wheel to spin and no picture of a die, and the page cannot draw names or answer letters directly; map them to numbers as described above. It cannot weight one option more heavily than another.

Nothing is saved between visits. The page keeps no history, so it cannot stop a number from coming back in a later list, and leaving the page clears the result. It also keeps no signed record, so it cannot prove to other people that a draw was fair.

To change the range, edit Minimum value or Maximum value: 1 to 10 or 1 to 20 work the same way. How many numbers has no cap. Above 10,000 numbers, the box shows the first 10,000, while Copy results and Download .txt contain all of them. JavaScript and Web Crypto are required; without them the page shows a message.

Questions

Can you give me a random number from 1 to 4?

Yes. The page opens on Minimum value 1, Maximum value 4 and How many numbers 1, so Generate numbers gives one number right away. Each of the four has a 25% chance. Select Generate again for another; a repeat of the last number has the same 25% chance as any other result.

How much is a 1/4 chance?

A 1/4 chance is 25%, or 0.25: on average the event happens once in every four tries. It does not happen exactly once per four tries, though. In five draws from 1 to 4, a given number is still missing 23.7% of the time, and it can also come up twice in a row.

Can this replace a four-sided die?

Yes, for the result. One draw from 1 to 4 has the same equal odds as a fair d4, taken from Web Crypto random bytes. For several dice, set How many numbers to the dice count and add the rolls yourself. The page does not add them, draw the die or keep a history.

Can you provide a random number generator for 1 to 10?

This is the same generator with a different range. Change Maximum value from 4 to 10 and select Generate numbers; each number from 1 to 10 then has a 10% chance. Reset takes the form back to 1 to 4. The general random number page has more on other ranges and decimals.