Random Number Between Two Numbers: How It Works
The calculator for this page is switched off while it is checked. The formula is below, and the worked example in the article shows how to use it by hand.
This calculator generates a random integer (whole number) between any two numbers you specify, inclusive of both endpoints. You enter a minimum and maximum value, and the calculator returns a uniformly distributed random number within that range. It is useful for picking lottery numbers, choosing a random item from a numbered list, or any situation where you need an unbiased random selection.
Formula
The calculator uses the standard linear mapping formula for a uniform integer distribution:
Random number = floor(min + (max – min + 1) × U)
Where:
- min = the lower bound of the range (inclusive), an integer.
- max = the upper bound of the range (inclusive), an integer.
- U = a random real number between 0 (inclusive) and 1 (exclusive), generated by a pseudorandom number generator.
- floor() = the function that rounds a real number down to the nearest integer.
The term (max – min + 1) is the total number of integers in the range. Multiplying U by this count gives a value from 0 up to (but not including) the count. Adding min shifts the result so it falls between min and max. The floor function ensures the final result is an integer.
Worked Example
Using the default values from the calculator (min = 1, max = 100):
- Calculate the count: 100 – 1 + 1 = 100.
- Suppose the random generator produces U = 0.473.
- Compute: 1 + (100 × 0.473) = 1 + 47.3 = 48.3.
- Apply floor: floor(48.3) = 48.
So the random number is 48. If U were 0.999, the result would be floor(1 + 99.9) = 100, showing that the maximum is included. If U were 0.000, the result would be floor(1) = 1, showing that the minimum is included.
How Random Number Generation Works
Computers cannot generate truly random numbers on their own; they use algorithms called pseudorandom number generators (PRNGs). These algorithms produce sequences of numbers that appear random but are actually deterministic, starting from an initial value called a seed. Common PRNGs include the Mersenne Twister and the linear congruential generator. The seed can be taken from the current time, system entropy, or other sources to make the sequence unpredictable in practice. For most everyday uses—games, sampling, simple simulations—PRNGs are sufficient. For cryptographic purposes, however, a cryptographically secure PRNG (CSPRNG) is required, which uses hardware entropy sources to ensure unpredictability.
How to Choose the Range
When using the calculator, consider the following:
- Decide whether the endpoints should be included. The calculator includes them, which is what most people expect (e.g., a dice roll of 1 to 6 includes 1 and 6).
- Use integers only. If you need a decimal, you can generate an integer and divide, or use a separate decimal random generator.
- For a list of items, assign each item a number from 1 to N, then generate a random number in that range to pick one item.
- If you need multiple random numbers, generate them one at a time; each result is independent.
Common Mistakes and Misconceptions
One frequent mistake is forgetting that the range is inclusive. If you ask for a number between 1 and 6, you want 1, 2, 3, 4, 5, or 6—not 1 to 5. The calculator handles this correctly, but many people manually code formulas that exclude the maximum. Another misconception is that random numbers are “due” to appear. If you roll a die and get 6 five times in a row, the next roll still has a 1/6 chance of being 6; past results do not influence future ones. Also, be aware that the uniformity of the distribution is only as good as the underlying generator. Poorly designed generators can produce noticeable patterns, but modern ones are well-tested.
Limitations and Alternatives
This calculator produces a single random integer per click. If you need a sequence of random numbers, you can click repeatedly, but each result is independent. For generating many numbers at once, you might use a spreadsheet function like RAND() or a programming language’s random library. For true randomness (e.g., for security or scientific drawing), consider using a hardware-based random number generator or a service that uses atmospheric noise. For simple uses, the calculator is perfectly adequate.
Frequently Asked Questions
Can I get a random decimal number instead of an integer?
This calculator only returns integers. To get a decimal, you could generate an integer and then divide by a power of 10, or use a dedicated decimal random generator. For example, to get a number between 0 and 1 with two decimal places, generate an integer from 0 to 100 and divide by 100.
Is the random number truly random?
No, it is pseudorandom, meaning it is generated by an algorithm. For everyday purposes, this is indistinguishable from true randomness. For cryptographic or high-stakes applications, you should use a cryptographically secure generator.
What if I enter the same minimum and maximum?
If min equals max, the only possible result is that number. The formula still works: count = 1, so the result is always min.
Can I use negative numbers?
Yes, the calculator accepts negative values. For example, a range from -10 to 10 includes all integers from -10 to 10. The formula works the same way.
Why do I sometimes get the same number twice in a row?
That is normal. Random sequences can have repeats. Over a large number of draws, each number should appear roughly equally often, but short runs can have duplicates.
How do I pick a random item from a list?
Assign each item a number from 1 to N, where N is the number of items. Then use the calculator with min=1 and max=N. The result tells you which item to choose.
Related
Formula used
in min | Minimum value | - | 1 | 0 in max | Maximum value | - | 100 | 0 out random | Random number | - | floor(min + (max - min + 1) * random()) | 0
Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.