Random numbers & Pseudo-Randomness
• Computer can not generate ‘truly’ random
numbers - no repeats, no pattern.
• Pseudo random numbers are possible:
- Effectively random, for a given purpose
- Satisfy certain mathematical tests
- All algorithms start with a starting ‘seed’.
- Different seeds produce different sequences
of random numbers
Random Number Generator: Role of the seed
• To generate a predictable sequence of random
numbers
• Change the seed to get a different sequence
• Each seed corresponds to a different starting point
(a long sequence of values follows)
• Use the same seed for testing and debugging
Seed = 243, Sequence = 3,1,4,5,7,2,8,9,0,4,7,3,6,8,2..
Seed = 107, Sequence = 5,7,3,2,7,8,9,0,2,2,6,1,9,5,…
A simple algorithm (for illustration)
N(i+1) = [ a * N(i) + c ] MOD k,
where a, c and k are constants
Let k = 65536 (i.e. gives a 16-bit number)
Let c = 61871, a = 4441
N(0) = seed = 0.
Will the numbers repeat?
Will the pattern repeat?
Why / why_not?
Results for seeds of 5,12, 45, 67, 89 and 95 are shown in the notes page.
Second (very simplistic) example using the simple algorithm
(but does not yield a realist range of possible outcomes)
N(i+1) = [ a * N(i) + c ] MOD k,
where a, c and k are constants
Let k = 10 (i.e. range is values 0 – 9)
let c = 3, a = 2
N(0) = seed = 0.
Sequence = 3, 9, 1, 5, 3, 9 …
N(0) = seed = 8.
Sequence = 9, 1, 5, 3, 9, 1 …
(Pattern repeats very soon into the sequence,
this is partly because the range of outcomes is
very limited, only {0,1,2,3,4,5,6,7,8,9})
© Copyright 2026 Paperzz