Pseudo-Random Number Generators

Context: FIT2086_MOC Β· the engine under every simulation, Bootstrap and permutation test Β· R usage (set.seed, runif, rnorm) βž” R Simulation and Random Sampling

Quick Revision

  • 🎯 Objective: a deterministic recurrence whose output resembles iid uniforms βž” the seed fixes the whole sequence βž” simulations become exactly repeatable.
  • ⚑ Key Constraint: same seed + same generator ⟹ identical sequence β€” the advantage (reproducibility) and the disadvantage (good seeding is crucial) are the same fact.

πŸ“ Core

  • Why β€œpseudo” βž” a computer is fully deterministic ⟹ no true randomness; a PRNG’s sequence is completely determined by the process and its state, yet is designed to have the statistical properties of independent random numbers.
  • Recurrence βž” , = transition function; the initial = seed (usually the current time, sometimes a β€œtrue” random source).
  • Uniforms first βž” the primitive output is , on ; every other distribution is built from uniforms.
  • Modern generator βž” SIMD-oriented Fast Mersenne Twister: fast, period up to before repeating; R’s default generator is the Mersenne Twister.
  • Other distributions βž” inverse-CDF procedure Β· Metropolis–Hastings Β· accept–reject Β· adaptive rejection sampling Β· slice sampling (named only) βž” in practice call rnorm(), rpois(), rexp().
  • LCG (teaching example) βž” β€” the current value alone determines the next ⟹ the first repeated value starts a cycle.

πŸ“Š Exam Execution Trace

LCG with seed , , , :

  • Output βž” ⟹ a repeating cycle of length β€” a toy period; a usable generator needs an astronomically long one.
  • R reproducibility βž” set.seed(5); runif(n = 10, min = 0, max = 1) run twice prints the same ten numbers; a different seed gives a different sequence.

⚠️ Common Mistakes

  • πŸ’‘ β€œRandom” output called truly random βž” it is deterministic given the seed; that is exactly what makes a simulation repeatable.
  • πŸ’‘ Re-seeding only once βž” one set.seed() fixes the starting state; the generator advances with every draw, so a later block differs unless re-seeded (R Simulation and Random Sampling).

🧠 Active Recall