Home / Math / Random Number Generator
Random Number Generator
Generate one or many random numbers between any two limits. Choose whole numbers or decimals and decide whether repeats are allowed. Randomness comes from the secure generator built into your browser.
How the numbers are generated
Every number is drawn with crypto.getRandomValues, the cryptographically secure generator that browsers expose. That is stronger than the Math.random function, whose algorithm is not designed to resist prediction.
A common mistake is to take a random 32-bit value and apply the remainder operator, as in x % 100. Because 232 is not a multiple of 100, the smaller results occur slightly more often. This tool avoids that modulo bias with rejection sampling: it masks a random value to the smallest bit width that covers the range and throws it away whenever it falls outside the range, then tries again. Every value in the range is therefore equally likely.
Choosing the options
- Whole numbers or decimals: decimals are picked on a fixed grid, for example 0.01 steps when you choose two decimal places, so 3.14 and 3.15 are equally likely. The limits are rounded inwards to that grid.
- Allow repeats: each draw is independent, like rolling a die many times. The same value can come up twice.
- Every number unique: numbers are drawn without replacement, like pulling balls from a drum. The count cannot exceed the number of possible values, and the tool reports an error if it does.
For small ranges the unique mode shuffles the full list of values with an unbiased partial Fisher-Yates shuffle. For huge ranges it redraws on a clash, which is rare.
Good and poor uses
Reasonable uses include choosing a raffle winner by entry number, assigning people to groups, sampling rows from a list, picking a number for a game, or generating test data. A clear procedure helps: number every entry from 1 upwards, set the range to match, and publish the result.
It is not a licensed lottery, and it should not be your only safeguard for passwords or encryption keys. Dedicated password managers and key-generation tools exist for that. Random sequences also look streaky: seeing the same digit three times in a row is normal and does not mean the generator is faulty.
Limits
The minimum and maximum must lie between -1,000,000,000 and 1,000,000,000, you can request up to 1,000 numbers at once, and decimals go up to six places. The summary rows show the smallest, largest, sum and mean of the numbers drawn in this run. They describe the sample, not the generator, so the mean of a small sample from 1 to 100 will rarely be exactly 50.5.
Worked example
Draw six different whole numbers from 1 to 49, the kind of selection used for a typical lottery-style pick. Each click gives a fresh set.
Inputs
| Minimum | 1 |
|---|---|
| Maximum | 49 |
| How many numbers | 6 |
| Type of number | Whole numbers |
| Repeats | Every number unique |
Result
6 numbers between 1 and 49, all different.
| Possible values in range | 49 |
|---|---|
| Smallest generated | 1 |
| Largest generated | 44 |
| Sum of generated numbers | 100 |
| Mean of generated numbers | 17 |
| Sorted list | 1, 4, 12, 18, 21, 44 |
Accuracy note: Results use standard double-precision arithmetic, so very large or very small values may be rounded. Check important results by another method.
Frequently asked questions
Is this random number generator truly random?
It uses the secure random source supplied by your browser or operating system, which is designed to be unpredictable. It is a high-quality pseudo-random source rather than a physical dice or radioactive decay.
What is modulo bias and why does it matter?
Taking a random value modulo a range that does not divide evenly makes some outcomes slightly more likely. Rejection sampling discards the awkward values so that every outcome has exactly the same probability.
Can I generate numbers without repeats?
Yes. Choose the unique option and the tool draws without replacement. It returns an error if you ask for more unique numbers than the range contains, for example 11 unique numbers from 1 to 10.
Are the minimum and maximum included?
Yes, both limits can appear. For whole numbers between 1 and 6 each of the six values has the same chance, just like a fair die.
Can I use this for a giveaway draw?
Yes, as a fair way to pick an entry number. Decide the entry numbering and the rules before you draw and keep a record, so that others can see the process was not changed afterwards.
Related calculators
References and sources
- NIST SP 800-90A: recommendations for random number generation using deterministic random bit generators.
- Web Crypto API specification, Crypto.getRandomValues, published by the W3C. Link