Enter the lower and upper limits and press "Calculate" to generate random numbers in that range. You can also set how many, the decimal places and whether repeats are allowed (everything except the limits can be left blank, which means 1 whole number, repeats allowed).
Table of Contents
-
What you can do on this page
-
What is this calculation used for?
-
How to Use
-
Formula
-
Probability of each value for random whole numbers (discrete uniform distribution)
-
How likely random decimals are (probability density of the continuous uniform distribution)
-
Average of random numbers (expected value of a uniform distribution)
-
Turning a random number from 0 to 1 into a random whole number in a range
-
A classic way to make pseudorandom numbers (linear congruential generator)
-
-
Symbols and terms
-
Good to know before you start
-
How to calculate it in Excel
-
How to calculate it in Google Sheets
-
How to calculate it in Python
-
How to write it in LaTeX and other math languages (copy and paste)
-
How to have ChatGPT do the calculation
-
DataChef Features
-
Related Features
-
NumberChef Calculators List
What you can do on this page
- Just enter a lower and an upper limit to get random numbers (numbers picked by chance) in that range on the spot
- You can make random decimals as well as whole numbers. Choose from 0 to 50 decimal places
- Generate up to 999 numbers at once, with or without repeats. When you make 2 or more, the result also shows them sorted in ascending and descending order, along with the order they were generated in
- Works for anything from a small range like 1 to 6 up to huge whole numbers with more than 20 digits
- A plain-language explanation of how random numbers work and copy-and-paste formulas for Excel, Google Sheets and Python are all on this page
What is this calculation used for?
Give each entrant or student a number and pick with random numbers, and the choice is fair, with no one's intentions involved. Everyone has the same chance of being picked (a uniform distribution). It is a drawing whose fairness is backed by math.
The white balls in Powerball, "5 numbers from 1 to 69 with no repeats", work in exactly this way, and there are 11,238,513 possible sets of them.
How can a poll of a few thousand people tell us what the whole country thinks, without asking every American? The answer is random sampling, choosing the people to ask with random numbers. Choosing on purpose would bias the results, so picking at random is what makes a survey trustworthy.
Random digit dialing (RDD), used in many opinion polls, creates the phone numbers themselves with random numbers, so that people with unlisted numbers have the same chance of being called.
Even a problem too complex to solve with a formula can be answered approximately by running tens of thousands of random trials and adding up the results. This is called the Monte Carlo method. It is used everywhere from risk calculations at banks and ensemble weather forecasts (running many forecasts with slightly different starting conditions) to research in physics and medicine.
Its theoretical foundation is the property you learn on this page: the average of random numbers gets closer to the expected value.
All the chance in video games, from dice rolls and card shuffles to loot drops and randomly generated maps, is made with pseudorandom numbers.
The fact that the same seed gives the same sequence is actually put to good use, in replay features and in sharing a world seed with friends so everyone plays the same map.
Encrypted connections for online shopping and one-time passwords only work because of random numbers, numbers an attacker cannot predict.
Ordinary pseudorandom numbers could be predicted, so they cannot be used here. Instead, cryptographically secure generators and hardware random number generators, which use physical events such as heat noise, are used. This is the most demanding use of random numbers, where their quality decides how safe the world is.
Formula
Symbols and terms
Symbols
| \(a\) | a | The lower limit of the range (this number or more). (Example - for random numbers from 1 to 100, \(a = 1\)) |
| \(b\) | b | The upper limit of the range (this number or less). (Example - for random numbers from 1 to 100, \(b = 100\)) |
| \(P(X=k)\) | P of X equals k | The probability that the random number \(X\) is exactly the whole number \(k\). For uniform random whole numbers, it is the same for every \(k\). |
| \(f(x)\) | f of x (probability density) | The height of the graph that shows how likely random decimals are (the probability density function). For a uniform distribution, the height is the same everywhere in the range. |
| \(E[X]\) | E of X (expected value) | The value that the average gets closer to when you generate many random numbers \(X\). E stands for "expectation". |
| \(u\) | u | A uniform random number from 0 up to (not including) 1. Most computer random numbers are first made in this form, then moved into the range you want. |
| \(\lfloor\ \rfloor\) | floor (floor function) | A symbol that drops the decimal part of the number inside and rounds it down to a whole number. (Example - \(\lfloor 3.2 \rfloor = 3\)) |
| \(X_n\) | X sub n | The \(n\)th value in a sequence of pseudorandom numbers. The starting value \(X_0\) is the seed. |
| \(\bmod\) | mod | The operation that gives the remainder of a division. (Example - \(38 \bmod 16 = 6\), because 38 divided by 16 is 2 with remainder 6) |
Terms
| random number | A number with no pattern that lets you predict what comes next, like the roll of a die. The generator on this page makes numbers picked at random from the range you set. |
| uniform distribution | A distribution where every value in the range is equally likely. For random whole numbers, every whole number has the same probability. For random decimals, the graph has the same height everywhere. |
| pseudorandom number | A number from a sequence made by a formula that looks random. The formula is called a PRNG (pseudorandom number generator). Almost all computer random numbers are pseudorandom numbers. |
| seed | The starting value for calculating pseudorandom numbers. Starting from the same seed always gives exactly the same sequence. Normally the seed is set automatically, for example from the current time, so each sequence looks different. |
| linear congruential generator | The most classic way to make pseudorandom numbers, by repeating "multiply, add, keep the remainder". It is ideal for learning how they work, but today higher-quality methods such as the Mersenne Twister are the norm in practice. |
| hardware random number generator | A device that makes random numbers from physical events, such as dice, coins, electrical noise in the atmosphere or heat noise in electronic circuits. Since no formula is involved, the numbers cannot be reproduced and come close to true random numbers. |
| expected value | The average of a chance outcome over many repeats. For uniform random numbers, the expected value is exactly the middle of the range. |
| random sampling | Choosing who or what to study at random, for example with random numbers, with no human choice involved. It is the basic way to avoid bias in statistical surveys. |
Good to know before you start
Here is what helps you use the calculation on this page with real understanding, not just by pressing the button.
| Division with remainders (Grade 4) |
|
| Decimals and rounding down (Grades 4–5) |
|
| Ratios and percents (Grade 6) |
|
| Basic probability (Grade 7) |
|
| Expected value (high school, Statistics) |
|
How to calculate it in Excel
| Lower limit a | 1 |
| Upper limit b | 6 |
| Probability of each whole number | =1/(B2-B1+1) |
| Lower limit a | 0 |
| Upper limit b | 10 |
| Probability density (graph height) | =1/(B2-B1) |
| Lower limit a | 1 |
| Upper limit b | 100 |
| Average (expected value) | =(B1+B2)/2 |
| Lower limit a | 1 |
| Upper limit b | 100 |
| Random whole number (changes on every recalculation) | =B1+INT(RAND()*(B2-B1+1)) |
| Current random number Xn | 7 |
| Multiplier a | 5 |
| Increment c | 3 |
| Divisor m | 16 |
| Next random number | =MOD(B2*B1+B3,B4) |
The first table shows about 0.1667 (= 1/6), the third shows 50.5, and the fifth shows 6.
RAND() in the fourth table makes a random number from 0 up to (not including) 1, in exactly the form of the conversion formula in the Formula section. Press F9 to get a new random number each time.
Excel also has the function =RANDBETWEEN(B1,B2), which gives the same kind of random whole number with a single function.
How to calculate it in Google Sheets
| Lower limit a | 1 |
| Upper limit b | 6 |
| Probability of each whole number | =1/(B2-B1+1) |
| Lower limit a | 0 |
| Upper limit b | 10 |
| Probability density (graph height) | =1/(B2-B1) |
| Lower limit a | 1 |
| Upper limit b | 100 |
| Average (expected value) | =(B1+B2)/2 |
| Lower limit a | 1 |
| Upper limit b | 100 |
| Random whole number (changes on every recalculation) | =B1+INT(RAND()*(B2-B1+1)) |
| Current random number Xn | 7 |
| Multiplier a | 5 |
| Increment c | 3 |
| Divisor m | 16 |
| Next random number | =MOD(B2*B1+B3,B4) |
Copy the whole table, paste it into cell A1, and replace the input numbers with your own.
How to calculate it in Python
import random
lower = 1 # lower limit
upper = 100 # upper limit
count = 5 # how many to generate
# random whole numbers (repeats allowed)
integers = [random.randint(lower, upper) for _ in range(count)]
# random whole numbers (no repeats)
unique_integers = random.sample(range(lower, upper + 1), count)
# random decimals
decimals = [random.uniform(lower, upper) for _ in range(count)]
print(f"Random whole numbers (repeats allowed): {integers}")
print(f"Random whole numbers (no repeats): {unique_integers}")
print(f"Random decimals: {decimals}")
# with a fixed seed, the same sequence comes back every time you run it (a property of pseudorandom numbers)
random.seed(42)
print(f"Random numbers with seed 42: {[random.randint(1, 100) for _ in range(3)]}")
How to write it in LaTeX and other math languages (copy and paste)
P(X = k) = 1 / (b − a + 1)
P(X = k) = \frac{1}{b - a + 1}
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
<mrow>
<mi>P</mi><mo>(</mo><mi>X</mi><mo>=</mo><mi>k</mi><mo>)</mo>
<mo>=</mo>
<mfrac>
<mn>1</mn>
<mrow><mi>b</mi><mo>−</mo><mi>a</mi><mo>+</mo><mn>1</mn></mrow>
</mfrac>
</mrow>
</math>
P(X = k) = 1/(b - a + 1)
1/(b - a + 1)
p := 1/(b - a + 1);
p = 1/(b - a + 1);
P(X = k) = 1/(b - a + 1)
f(x) = 1 / (b − a)
f(x) = \frac{1}{b - a}
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
<mrow>
<mi>f</mi><mo>(</mo><mi>x</mi><mo>)</mo>
<mo>=</mo>
<mfrac>
<mn>1</mn>
<mrow><mi>b</mi><mo>−</mo><mi>a</mi></mrow>
</mfrac>
</mrow>
</math>
f(x) = 1/(b - a)
1/(b - a)
f := 1/(b - a);
f = 1/(b - a);
f(x) = 1/(b - a)
E[X] = (a + b) / 2
E[X] = \frac{a + b}{2}
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
<mrow>
<mi>E</mi><mo>[</mo><mi>X</mi><mo>]</mo>
<mo>=</mo>
<mfrac>
<mrow><mi>a</mi><mo>+</mo><mi>b</mi></mrow>
<mn>2</mn>
</mfrac>
</mrow>
</math>
E[X] = (a + b)/2
(a + b)/2
mean := (a + b)/2;
mean_x = (a + b)/2;
E[X] = (a + b)/2
n = a + ⌊u × (b − a + 1)⌋
n = a + \lfloor u \times (b - a + 1) \rfloor
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
<mrow>
<mi>n</mi>
<mo>=</mo>
<mi>a</mi>
<mo>+</mo>
<mo>⌊</mo>
<mi>u</mi>
<mo>×</mo>
<mo>(</mo><mi>b</mi><mo>−</mo><mi>a</mi><mo>+</mo><mn>1</mn><mo>)</mo>
<mo>⌋</mo>
</mrow>
</math>
n = a + |__ u xx (b - a + 1) __|
a + Floor[u*(b - a + 1)]
n := a + floor(u*(b - a + 1));
n = a + floor(u*(b - a + 1));
n = a + ⌊u × (b - a + 1)⌋
Xₙ₊₁ = (a·Xₙ + c) mod m
X_{n+1} = (a X_n + c) \bmod m
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
<mrow>
<msub><mi>X</mi><mrow><mi>n</mi><mo>+</mo><mn>1</mn></mrow></msub>
<mo>=</mo>
<mo>(</mo>
<mi>a</mi><msub><mi>X</mi><mi>n</mi></msub>
<mo>+</mo><mi>c</mi>
<mo>)</mo>
<mo>mod</mo>
<mi>m</mi>
</mrow>
</math>
X_(n+1) = (a X_n + c) mod m
Mod[a*x + c, m]
X[n + 1] := (a*X[n] + c) mod m;
x_next = mod(a*x + c, m);
X_(n+1) = (a X_n + c) mod m
How to have ChatGPT do the calculation
You are an assistant for generating random numbers. Do the following by actually running Python code, and base your answer only on the numbers from the execution result (random numbers cannot be made without running code, so do not guess or make up any numbers). 1. Generate 5 random whole numbers from 1 to 100 with no repeats. 2. Sort those 5 numbers in ascending order. 3. Generate 1 random decimal from 0.2 to 112.5 with 3 decimal places. Show the code you used and the numbers from the execution result.
How to Use
-
1Enter your numbersType the numbers you want to calculate with into the input fields
-
2CalculatePress the "Calculate" button
-
3Check the resultThe result appears on the spot. The same page also explains the idea behind the calculation and the formula
DataChef Features
No technical knowledge required.
Intuitive and user-friendly operation.
Can be used without registering personal information.
Automatic file deletion by clicking "download".
and rapid file conversion.
No attribution required.
No need to contact us for commercial use permission.
