Randomize a Series
Menu location: Analysis_Randomization_Series X to Y
This function randomizes a series of integers for which you define the beginning and end points of the series.
For example, randomizing numbers from 6 to 10 is like shuffling 5 cards labelled 6 to 10. To randomize a series of 49 possible lottery numbers enter x as 1 and y as 49:
Random allocation of numbers in a series
| Randomized with seed: 10 | |
| 1 | 43 |
| 2 | 17 |
| 3 | 14 |
| 4 | 31 |
| 5 | 34 |
| 6 | 40 |
| 7 | 41 |
| 8 | 42 |
| 9 | 16 |
| 10 | 2 |
| 11 | 37 |
| 12 | 7 |
| 13 | 19 |
| 14 | 11 |
| 15 | 30 |
| 16 | 48 |
| 17 | 13 |
| 18 | 25 |
| 19 | 46 |
| 20 | 4 |
| 21 | 18 |
| 22 | 28 |
| 23 | 12 |
| 24 | 32 |
| 25 | 49 |
| 26 | 22 |
| 27 | 36 |
| 28 | 45 |
| 29 | 44 |
| 30 | 5 |
| 31 | 3 |
| 32 | 39 |
| 33 | 6 |
| 34 | 10 |
| 35 | 27 |
| 36 | 26 |
| 37 | 8 |
| 38 | 47 |
| 39 | 9 |
| 40 | 24 |
| 41 | 21 |
| 42 | 35 |
| 43 | 33 |
| 44 | 20 |
| 45 | 29 |
| 46 | 23 |
| 47 | 1 |
| 48 | 15 |
| 49 | 38 |
You could then take the first, say six, as your random selection.
The seed is printed with the series so that the series can be produced again: enter 10 as the seed to repeat the series above.
Technical validation
Robust (pseudo-)random number generation is used, see random number generation.
R code
This R code reproduces the illustration above, with the different series that R's own generator gives for the same seed. It needs no packages and was checked with R 4.6.1. Paste it into R, or save it as a script and run it.
# Randomizing a series of integers: the StatsDirect help illustration (the numbers
# 1 to 49, as in a lottery, put in a random order with seed 10) in R
x <- 1
y <- 49
seed <- 10
# sample(x:y) returns the integers x to y in a random order, every order being
# equally likely. StatsDirect and R each have their own Mersenne Twister generator
# and their own way of turning its output into a random order, so the same seed
# gives a different series in R: the two columns of the output are the same, the
# numbers are not. Keep the seed with the series, as either program can then repeat it.
# (For a series of one number, x = y, sample(x:y) would instead shuffle 1 to x.)
set.seed(seed)
series <- sample(x:y)
cat("Random allocation of numbers in a series\n")
cat("Randomized with seed:", seed, "\n")
print(data.frame(position = seq_along(series), number = series), row.names = FALSE)
# Six lottery numbers: the first six of the series, or equivalently sample(x:y, 6),
# which draws six of the numbers without replacement
cat("The first six:", head(series, 6), "\n")
# The five cards labelled 6 to 10
set.seed(seed)
cat("Cards 6 to 10 shuffled:", sample(6:10), "\n")