Tutorials › Exam ASTAM - Advanced Short-Term Actuarial Mathematics › Pseudo-Random Uniform Numbers

Exam ASTAM · Random Variate Generation · Tutorial 586 of 979

Pseudo-Random Uniform Numbers

Understand the role of pseudo-random uniform numbers in simulation and reproduce short sequences by tracking a generator’s seed and state.

Beginner 9 min read

What You'll Learn

  • Distinguish a pseudo-random sequence from genuinely random observations
  • Interpret a generator’s state, seed, and uniform output
  • Calculate outputs from a specified linear congruential generator
  • Explain why a fixed seed reproduces a sequence
  • Identify endpoint conventions and common limits of simple generators
  • Track how draw order affects reproducibility

Why Uniform Numbers Are Simulation Inputs

A simulation algorithm needs numerical inputs that behave like draws from a specified probability distribution. A common starting point is a sequence of numbers intended to behave like independent observations from a uniform distribution on the unit interval. Other algorithms can then use those inputs to produce values for a model of interest. The uniform numbers are therefore a basic computational resource, not usually the final simulated outcomes.

Computers ordinarily generate these numbers with a deterministic procedure. The resulting values are called pseudo-random: they can have useful statistical properties and appear irregular, but the sequence is determined by its initial state and the algorithm. This distinction matters when interpreting a simulation and when trying to reproduce or audit its results.

Definition: A pseudo-random number generator (PRNG) is a deterministic algorithm that updates an internal state and returns numerical outputs. A seed specifies the initial state. A PRNG’s uniform outputs are designed to behave approximately like draws from a uniform distribution on a stated interval, commonly \([0,1)\), but the outputs are not genuinely independent random variables.

In an ideal mathematical model, a uniform random variable \(U\) on \([0,1)\) assigns probability \(b-a\) to any interval \([a,b)\) with \(0 \leq a \leq b \leq 1\). A computer’s finite collection of possible outputs cannot realize every real number in that interval. Instead, a PRNG produces values from a finite set, with the intended behavior judged by how well its outputs and sequences approximate the properties needed for the simulation.

A PRNG is described by more than a seed. Its algorithm, parameters, output convention, and state-update rules determine the sequence. The same seed with a different generator, or even a different implementation of the same nominal generator, need not give the same outputs. Reproducibility requires recording enough information to identify both the initial state and the procedure.

A Simple Generator and Its Uniform Outputs

A linear congruential generator (LCG) is a useful small example for hand calculations. It is not a recommendation for serious simulation: small versions have visibly limited output sets and short cycles. Let \(X_n\) be the integer state after \(n\) updates. Given positive integer modulus \(m\), multiplier \(a\), increment \(c\), and initial state \(X_0\), define

$$ X_{n+1}=(aX_n+c)\bmod m. $$

The notation “mod \(m\)” means to take the remainder after division by \(m\), so each state is an integer in \(\{0,1,\ldots,m-1\}\). One common conversion to a unit-interval output is

$$ U_{n+1}=\frac{X_{n+1}}{m}. $$

This convention produces values in \([0,1)\), not \((0,1)\): a state of zero gives \(U=0\), while the largest possible state, \(m-1\), gives \(1-1/m\). Other generators or software may use a different endpoint convention. An implementation should document its convention, especially when a later calculation is sensitive to an endpoint.

Worked Example: Generate and Scale Five States

Use the LCG with \(m=16\), \(a=5\), \(c=1\), and seed \(X_0=3\). Find the next five states and their uniform outputs. The method is to apply the recurrence once per state, reduce to a remainder modulo 16, and divide the resulting state by 16.

First state. \(X_1=(5(3)+1)\bmod 16=16\bmod 16=0\), so \(U_1=0/16=0\).

Second state. \(X_2=(5(0)+1)\bmod 16=1\), so \(U_2=1/16=0.0625\).

Third state. \(X_3=(5(1)+1)\bmod 16=6\), so \(U_3=6/16=0.3750\).

Fourth state. \(X_4=(5(6)+1)\bmod 16=31\bmod 16=15\), so \(U_4=15/16=0.9375\).

Fifth state. \(X_5=(5(15)+1)\bmod 16=76\bmod 16=12\), so \(U_5=12/16=0.7500\).

The states are \(0,1,6,15,12\), and the corresponding outputs are \(0,0.0625,0.3750,0.9375,0.7500\). Each output is in \([0,1)\), as required by this conversion. The common mistake this method avoids is dividing the unreduced value by 16: for example, \(31/16\) is not the fourth uniform output; the state is the remainder \(31\bmod 16=15\), giving \(15/16\).

Why a Seed Reproduces a Sequence

Reproducibility follows directly from determinism. If two runs use the same initial state and the same update rule, their first updated states agree. Applying the same rule to equal states produces equal next states, so every subsequent state agrees as well. This can be expressed as an induction.

Justification: Suppose two runs use the same deterministic update function \(g\) and have the same seed \(X_0\). Their states agree at \(n=0\). If their states agree at step \(n\), then both next states equal \(g(X_n)\), so they agree at step \(n+1\). By induction, all states—and any outputs computed from those states—are identical for as many steps as both runs use the same procedure.

The seed is not itself a request for “more randomness,” and choosing a different seed does not guarantee a statistically better sequence. It selects a starting state. For a particular generator, different seeds may lead to different sequences; some generators can even send certain seeds into short or unsuitable cycles. Seed-handling rules are part of the generator specification.

Worked Example: Compare Two Seeds

Use \(m=16\), \(a=5\), and \(c=1\) again, but start with seed \(X_0=4\). Calculate five outputs and compare them with the sequence from seed 3. The calculation method is unchanged; only the starting state differs.

First state: \(X_1=(5(4)+1)\bmod 16=21\bmod 16=5\), giving \(U_1=5/16=0.3125\).

Second state: \(X_2=(5(5)+1)\bmod 16=26\bmod 16=10\), giving \(U_2=10/16=0.6250\).

Third state: \(X_3=(5(10)+1)\bmod 16=51\bmod 16=3\), giving \(U_3=3/16=0.1875\).

Fourth state: \(X_4=(5(3)+1)\bmod 16=16\bmod 16=0\), giving \(U_4=0/16=0\).

Fifth state: \(X_5=(5(0)+1)\bmod 16=1\), giving \(U_5=1/16=0.0625\).

This seed gives states \(5,10,3,0,1\) and outputs \(0.3125,0.6250,0.1875,0,0.0625\). The earlier seed 3 produced \(0,1,6,15,12\) as its first five states, so the displayed starts differ. For this small generator, the state reached from seed 4 eventually overlaps the sequence from seed 3; a different seed does not imply a permanently distinct or independent stream. The purpose of the example is to show how the seed changes the starting point, not to claim that this small generator has high-quality randomness.

Draw Order and Reproducible Simulation

In a simulation, outputs are consumed in a particular order. A first model component may use one or more uniform inputs, followed by another component that uses the next outputs. If a change adds an extra draw, subsequent components can receive different inputs even though the original seed is unchanged. Reproducing a simulation therefore requires knowing how many outputs are used and in what order, not merely knowing the seed.

Worked Example: Track Outputs Across Two Components

Use the LCG with \(m=16\), \(a=5\), \(c=1\), and seed 3. A hypothetical simulation component A consumes the first two uniform outputs, and component B consumes the next three. List the inputs each component receives. Then suppose component A is changed to consume one additional output and identify the new inputs for component B.

The first five outputs, calculated from the recurrence, are \(0,0.0625,0.3750,0.9375,0.7500\). With the original draw plan, component A receives the first two, \(0\) and \(0.0625\). Component B receives the next three, \(0.3750\), \(0.9375\), and \(0.7500\).

If component A now consumes three outputs, it receives \(0\), \(0.0625\), and \(0.3750\). Component B then starts at the fourth output and receives \(0.9375\) and \(0.7500\). A third input for B would be the sixth output: \(X_6=(5(12)+1)\bmod 16=61\bmod 16=13\), so \(U_6=13/16=0.8125\). Thus B’s three new inputs are \(0.9375\), \(0.7500\), and \(0.8125\).

The seed and generator did not change, but component B’s inputs did because the draw allocation changed. The common mistake this example avoids is assuming that a fixed seed alone guarantees identical results for every component after the simulation’s structure has been modified.

What Uniform Outputs Do—and Do Not—Guarantee

A uniform output sequence is useful only if its statistical behavior is adequate for the task. A generator’s outputs may have patterns, serial dependence, or too few possible values. The LCG example makes the finite set visible: with \(m=16\), outputs can only be multiples of \(1/16\). A large practical generator can offer a much finer set, but fineness by itself does not establish good statistical behavior.

A useful distinction is between the target model and its computational approximation. The target may call for independent uniform random variables. The program supplies a deterministic sequence designed to approximate that ideal. Statistical testing and careful generator selection are used to assess whether the approximation is suitable; they do not turn a deterministic sequence into genuine independence.

The output interval must also match the convention expected by the next procedure. For example, a generator returning \([0,1)\) can return zero, while a different convention might exclude zero. Do not silently replace an endpoint value, or assume that every software package uses the same interval. Follow the documented convention and the requirements of the algorithm that consumes the outputs.

1
Identify the generator.
Record its algorithm, relevant parameters, and output convention. A seed alone does not specify a sequence.
2
Set the initial state.
Use the stated seed and apply any documented seed-conversion rules.
3
Track state and draws.
Update the state in order, apply the specified output conversion, and keep track of which model component consumes each output.
4
Preserve reproducibility information.
For a repeatable run, retain the generator specification, seed or initial state, software details where relevant, and draw-order assumptions.

For actuarial simulation work, pseudo-random uniform numbers are the common inputs from which model-specific random quantities are generated. Knowing how the inputs are produced helps candidates interpret a simulation procedure, reproduce a calculation, and diagnose why two runs differ. It also prevents overstating what a seed accomplishes: it makes a specified deterministic run repeatable, but does not by itself establish that the generated sequence is statistically adequate.

Key takeaway: A pseudo-random uniform sequence is a deterministic, finite computational approximation to ideal uniform inputs. To reproduce it, specify both the generator and its seed; to reproduce a simulation’s component results, also preserve the output order and allocation.

Check Your Understanding

For each problem, track the stated generator and distinguish the seed, state, and uniform output.

  1. An LCG has \(m=10\), \(a=3\), \(c=1\), and seed \(X_0=2\). Find the next two states and their outputs using \(U_n=X_n/m\). (Answer: \(X_1=7,\ X_2=2;\ U_1=0.7,\ U_2=0.2\))
  2. For the generator in Question 1, a second run uses the same seed and exactly the same update and output rules. What are its first two outputs, and why? (Answer: \(0.7,\ 0.2\); determinism gives the same states and outputs from the same seed.)
  3. An LCG uses \(m=12\), \(a=5\), \(c=1\), and seed \(X_0=2\). Find the first three states and outputs. (Answer: states \(11,8,5\); outputs \(11/12, 2/3, 5/12\).)
  4. A simulation uses the outputs from Question 3. Component A consumes the first output and component B consumes the next two. If A is changed to consume two outputs, what outputs does B receive? (Answer: \(5/12\) is B’s only output among the first three; its next output is \(X_4=(5(5)+1)\bmod12=2\), or \(1/6\), so B receives \(5/12\) and \(1/6\) if it still requires two inputs.)
  5. A generator documents outputs on \([0,1)\). A displayed output equals \(0\). Is this outside the stated interval, and does that alone prove the generator is unsuitable? (Answer: No; zero is included in \([0,1)\), and that value alone does not establish whether the generator is suitable.)
Clinical Biostats