How Are Random Numbers Generated? Range Mapping, Repeat Probability and Fair Draws
Updated: November 6, 2026 · AracMerkezi
▶ Open Random Number Generator
We need random numbers to hold a draw, set a duty order, roll a die in a game or generate test data. If the randomness is not reliable, the result can be unfair. In this guide, we show with calculations how a computer produces a random number, how that number is turned into a range such as "between 1 and 100," the probability of the same number coming up again, and how many different outcomes a draw can have.
How are random numbers generated?
Computers provide randomness in two ways:
- Pseudo-random: Produced by a mathematical formula; it is fast but its output depends on the starting value.
- Secure (cryptographic) random: Fed by sources of unpredictability collected by the operating system; it is very hard to predict. Browsers offer it through the
cryptointerface.
The tools on this site use the browser's secure random number generator.
A random number in a given range
You set the smallest and largest whole numbers and write how many numbers you want. For example, you can ask for 5 numbers between 1 and 100. The end values are included; the same number can come up more than once.
Example 1: Mapping a number between 0 and 1 to a range
The generator gives a raw number between 0 and 1 (1 excluded). The formula to turn it into an integer range is: result = minimum + floor(r × (maximum − minimum + 1)). If the range is 1–100, the number of elements is 100.
- r = 0.5 → 1 + floor(0.5 × 100) = 1 + 50 = 51.
- r = 0 → 1 + 0 = 1 (lower end).
- r = 0.999 → 1 + floor(99.9) = 1 + 99 = 100 (upper end).
The formula includes the end values too. The most common mistake is forgetting the "+ 1" part: if you multiply by 99 instead of 100, the number 100 never appears.
Example 2: Why does the remainder operation cause a slight bias?
Generators often give a large 32-bit integer and map it to the range with a remainder (mod) operation. Let's see the logic with a small example: suppose there are 256 equally likely values from 0 to 255, and we map the result to 0–99 with the remainder after dividing by 100. Since 256 = 2 × 100 + 56:
- The 56 results from 0 to 55 each come from 3 values (probability 3/256 ≈ 1.17%).
- The 44 results from 56 to 99 each come from 2 values (probability 2/256 ≈ 0.78%).
So some numbers are 1.5 times as likely as others. With 32-bit values there are 2³² = 4,294,967,296 values; divided by 100 that leaves 42,949,672 full rounds and a remainder of 96, so 96 results come up one more time than the others. The relative difference is about 1 / 42,949,672 ≈ 2.3 × 10⁻⁸. The tool on this site uses the remainder operation; in small ranges such as 1–100, the bias is practically negligible, but the larger the range, the more noticeable the difference becomes. Software that wants to remove the bias discards values above the limit and draws again.
Example 3: Can the same number come up again?
If you generate 5 numbers between 1 and 100 and each draw is independent, the probability that all the numbers are different is: (100/100) × (99/100) × (98/100) × (97/100) × (96/100) ≈ 0.9035. So the probability that at least one number repeats is about 9.65%. When you ask for 10 numbers, this probability rises to about 62.8%. Although it seems against intuition, repeats are normal in random series; if you want results without repeats, use the draw tool.
Drawing lots
Write the candidates one per line and set how many people to choose. The tool picks without repeats. For example, you can choose 3 people from among 20.
Example 4: What are the odds when choosing 3 from 20?
- Number of different triples (order does not matter): C(20, 3) = 20 × 19 × 18 / 6 = 1,140.
- Probability that a particular person is chosen: 3 / 20 = 15%.
- If order matters (1st, 2nd, 3rd chosen): 20 × 19 × 18 = 6,840 different orderings.
Every triple is equally likely; that is, the chance of any particular triple is 1 / 1,140 ≈ 0.088%. If you need a ranking (1st prize, 2nd prize), announce in advance that the order the tool produces will be the prize order.
Tips for a fair draw
- Share the participant list with everyone first.
- Hold the draw live and share your screen.
- Set the rules (how many people, whether there are substitutes) beforehand.
- Announce the result in writing.
Dice, coin flips and other uses
For a die, you can generate a number in the range 1–6, and for a coin flip a number in the range 1–2. In games and entertainment, the result depends entirely on chance. For probability interpretations, see the guide to dice rolls and coin flips; for permutation and combination logic, the factorial and combination guide is useful.
A warning about official draws
Promotional, prize or public draws are subject to regulation and may require supervision by a notary or an authorized institution. This tool is for entertainment and everyday use; it is not a substitute for draws with legal validity.
Use for security purposes
For generating passwords, keys or security tokens, prefer dedicated tools; for example, the password generator uses secure randomness. Do not use values made with a simple random number for security.
Common mistakes
- Interpreting a number not coming up for a long time as "its turn has come"; each draw is independent.
- Forgetting the "+ 1" and leaving out the upper end.
- Using the random number tool when you want results without repeats; the draw tool picks without repeats.
- Using a simple random generator for security values.
- Not announcing the draw rules in advance.
When to use it and its limits
It is suitable for everyday decisions, picking in class, games and test data. Randomness does not have to be repeatable; that is, if you run the same draw again you will not get the same result. If you need a reproducible result (for example, re-creating a scientific simulation), you use a generator whose starting value can be fixed; this tool is not like that.
Try the Random Number Generator and Random Draw / Selection tools. For a secure password, the Password Generator, and for ID generation, the UUID Generator can be used.
Frequently asked questions
Is the random number generator reliable?
The tool uses the browser's secure random number generator; it is suitable for entertainment and everyday use.
Can the same number come up more than once?
In random number generation, yes; in a draw, the candidates are chosen without repeats.
Can it be used in an official draw?
No; draws with legal validity may require supervision by a notary or an authorized institution.
Tools mentioned in this guide
More guides
- How to Create a Secure Password: Length, Entropy and 8 Rules – How to create a secure password: password strength in bits, random-word passphrases, command-line generation and eight practical rules.
- Dice Roller and Coin Flip: A Guide to Probability and Fair Decisions – How do online dice rolls and coin flips work? Dice sum probabilities, the expected result of 10 coin flips and practical ways to make fair decisions.
- How to Convert HEX to RGB Color Codes: Step-by-Step Examples – How to convert a HEX color code to RGB and back: hexadecimal basics, short and 8-digit HEX, darkening math and verified JavaScript and Python snippets.
- What Is Fake Test Data? A Guide to Safe Mock Data for Testing and Demos – What is fake test data and why not use real customer data? Reserved example.com domains, edge-case records, pagination math, and JSON/CSV and UUID use.
- How to Spot a Phishing Email: Protection Guide – How to spot a phishing email? 10 signs of fake messages, how to check a link, first steps if you clicked, and how to report to USOM, Turkey's cyber response center.
This article is for general information only and is not legal, financial or medical advice. We are not an official institution.