Random samples and random numbers in Google Sheets
Excel's ToolPak has two tools for randomness: Sampling picks values from a range, and Random Number Generation fills a range with numbers from a distribution. StatPak has both, with a seed option so you can get the same results again.
Draw a random sample
An auditor wants to check 5 of 20 invoices. The invoice numbers are in column A.
| A | |
|---|---|
| 1 | Invoice |
| 2 | 10401 |
| 3 | 10404 |
| 4 | 10407 |
| 5 | 10410 |
| 6 | 10413 |
| 7 | 10416 |
| 8 | 10419 |
| 9 | 10422 |
| 10 | 10425 |
| 11 | 10428 |
| 12 | 10431 |
| 13 | 10434 |
| 14 | 10437 |
| 15 | 10440 |
| 16 | 10443 |
| 17 | 10446 |
| 18 | 10449 |
| 19 | 10452 |
| 20 | 10455 |
| 21 | 10458 |
- Open Extensions, StatPak, Data Analysis and choose Sampling.
- Input range:
A1:A21with Labels in first row ticked. - Sampling method: Random. Number of samples: 5.
- Random seed: 2026 (optional, see below). Click Run.
| 10428 |
| 10419 |
| 10440 |
| 10437 |
| 10410 |
As in Excel, random sampling draws with replacement: each pick is from the full list, so the same value can appear twice. If you need 5 different invoices, draw a few extra and drop repeats, or use the formula method below.
Periodic (systematic) sample
Choose Periodic with Period 4 to take every 4th value, starting with the 4th:
| 10410 |
| 10422 |
| 10434 |
| 10446 |
| 10458 |
Periodic sampling is useful for picking one point per cycle, for example the same quarter from each year of quarterly data.
Generate random numbers
To simulate test scores with mean 100 and standard deviation 15 for two groups of 8:
- Choose Random Number Generation.
- Number of variables: 2 (columns). Number of random numbers: 8 (rows).
- Distribution: Normal, Mean 100, Standard deviation 15.
- Random seed: 42. Click Run.
| 85.65757 | 95.90461 |
| 72.37559 | 82.88677 |
| 92.05849 | 118.4289 |
| 95.97223 | 72.9731 |
| 90.01001 | 50.81384 |
| 108.4793 | 115.051 |
| 122.5645 | 105.7591 |
| 116.6494 | 115.4542 |
The other distributions are Uniform (between two values), Bernoulli (0 or 1 with probability p), Binomial (successes in n trials), Poisson, Patterned (a repeating sequence such as 1, 1, 2, 2, 3, 3) and Discrete (values with probabilities you list in a two-column range).
What the seed does
With a seed, the same settings give the same numbers every time: running the example above again with seed 42 reproduces the table exactly. That lets a teacher, classmate or reviewer check your work. Leave the seed blank for a fresh set each run. The output is plain values, so it does not change when the sheet recalculates.
A seed reproduces results within StatPak. Excel uses a different random number generator, so the same seed in Excel gives different numbers.
With formulas
- Uniform numbers:
=RANDARRAY(8, 2)or=RANDBETWEEN(1, 100)for whole numbers. - Normal numbers:
=NORM.INV(RAND(), 100, 15). - Random sample without repeats:
=ARRAY_CONSTRAIN(SORT(A2:A21, RANDARRAY(20), TRUE), 5, 1). - Every 4th value:
=FILTER(A2:A21, MOD(ROW(A2:A21) - 1, 4) = 0).
Sheets' random functions have no seed and recalculate after every edit. To keep a result, copy it and use Edit, Paste special, Values only.