Language: English

tools / random

random/

Random numbers and a wheel picker. Uses crypto.getRandomValues with rejection sampling, so results are unbiased.

Result

What is a uniform random integer

A uniform random integer means every integer in the range has the same chance of being drawn. This page takes 32-bit random numbers from the browser's crypto.getRandomValues and removes modulo bias with rejection sampling, generating up to 10000 integers at a time or drawing one from a wheel of up to 50 options.

How it works: throw away the few values that cause bias

ECMA-262 only requires Math.random to return approximately uniform numbers in [0, 1) with an algorithm chosen by the browser, without any guarantee that they are hard to predict; Web Cryptography specifies that crypto.getRandomValues fills in cryptographically secure random bytes, so this page uses only the latter.

A 32-bit random number has 2^32 = 4294967296 possible values; for a range of 10 integers that does not divide evenly and leaves 6, so taking the remainder modulo 10 directly would give 0 to 5 one extra chance each over 6 to 9. This page throws away the 6 values from 4294967290 upward and draws again, so the rest split evenly over the 10 numbers.

Without duplicates, if the range has at most 1000000 integers and the count to draw is more than a quarter of the range, a partial Fisher–Yates shuffle is used; otherwise a repeated number is simply drawn again.

Sources

FAQ

Is this truly random, and can I use it for a prize draw?

It uses the browser's built-in crypto.getRandomValues, a cryptographically secure pseudo-random generator that is much harder to predict than Math.random. There is no seed input and no record of results, so a draw can't be reproduced or verified afterwards; if you need a publicly verifiable draw, this isn't the right tool.

I get "Min and max must be integers". Can it generate decimals?

No, it only generates integers. Min and max accept plain digits, optionally with a minus sign, but no decimal point, thousands separator or unit. For one decimal place, scale the range up by 10, for example 0 to 1000, and divide each result by 10 yourself to get one-decimal values from 0 to 100. The count is 1–10000, and min and max can be up to 2^53−1 in absolute value.

How do I fix "Without duplicates, the count can't exceed the number of integers in the range"?

"Allow duplicates" is unticked by default, so from 1 to 10 you can draw at most 10 different numbers, and asking for 20 gives this message. Either widen the range or tick "Allow duplicates".

How do I copy the results, and why is the output sometimes one line and sometimes many?

Up to 20 numbers are shown on one line separated by commas; more than 20 are shown one per line, which pastes into a spreadsheet as a single column. The "Copy" button at the top right of the result box copies everything, and "Sort ascending" sorts the numbers first. You can generate up to 10000 numbers at a time.

Is the wheel result truly random, or decided by the animation?

The result is drawn with crypto.getRandomValues before the wheel starts to turn. The animation only rotates to the matching spot, so how long it spins or when you press the button has no effect on the odds, and every slice has the same chance. The spin lasts about 5 seconds; if your system has "reduce motion" turned on, the animation is skipped and the result appears immediately.

How can I make one option more likely on the wheel?

Write it on more than one line. The wheel makes one slice per line and every slice has the same chance, so an option written on 2 lines gets 2 slices and double the odds. Blank lines and spaces at the start or end of a line are ignored, but duplicate lines are not merged. The limit is 50 options; extra lines beyond the first 50 are ignored, and a message tells you so.

How do I stop the wheel from picking the same person twice?

Tick "Remove winner after each spin". After each draw the winning option is deleted from the options box (if several lines share the same text, only the first one is removed), so it can't come up again. Drawn names are listed in order under "Drawn", up to 100 entries, and "Clear history" empties the list.

Are my options and results saved?

Nothing is uploaded or saved. The options, the results and the "Drawn" list exist only in the current page; after a refresh the options go back to the default examples and the list is empty. Save any options you want to keep yourself.