Author-reviewedEvidence: highv1.0.0

Random Number Generation

Random number generation supplies the uncertain draws used in probabilistic sensitivity analysis, microsimulation, discrete-event simulation, bootstrap procedures, and other stochastic analyses.

Last reviewed byDr Darrin Baines

Concept Architecture

Random Number Generation

In most health-economic models these values are pseudorandom: a deterministic algorithm produces a sequence that behaves like random draws for the intended statistical purpose.

Randomness, pseudorandomness, and state

A physical random-number generator derives values from an entropy-producing process, whereas a pseudorandom number generator (PRNG) advances a finite internal state using a deterministic rule. For a fixed algorithm and initial state, the sequence is exactly reproducible. The state transition can be represented as follows:

Sn+1=T(Sn),Un=g(Sn),0≤Un<1,S_{n+1}=T(S_n), \qquad U_n=g(S_n), \qquad 0\le U_n<1,

where SnS_n is the generator state, TT is the state-transition function, and gg maps the state to a nominally uniform value UnU_n. A seed initializes the state, but the complete state—not merely a remembered seed—is generally required to resume an interrupted computation at the exact next draw.

Period and statistical quality

Because a PRNG has finitely many states, its sequence eventually repeats; the maximum number of values before repetition is its period. A long period is necessary for large simulations but is not sufficient: useful generators must also avoid detectable non-uniformity, serial dependence, lattice structure, and poor behaviour in higher dimensions.

A linear congruential generator illustrates the mechanics:

Xn+1=(aXn+c) mod m,Un=Xnm.X_{n+1}=(aX_n+c)\bmod m, \qquad U_n=\frac{X_n}{m}.

For the toy settings m=16m=16, a=5a=5, c=1c=1, and X0=3X_0=3, the successive states are X1=0X_1=0, X2=1X_2=1, X3=6X_3=6, and X4=15X_4=15, giving U1=0U_1=0, U2=0.0625U_2=0.0625, U3=0.375U_3=0.375, and U4=0.9375U_4=0.9375. This small example is transparent enough for teaching but is not suitable for production modelling.

From uniform draws to model quantities

Most simulation libraries begin with approximately independent draws from U(0,1)U(0,1) and transform them into the required distribution. If FF is a continuous cumulative distribution function, inverse-transform sampling maps each uniform draw to the target distribution. The construction is

X=F−1(U).X=F^{-1}(U).

For an exponential time to event with rate λ\lambda, the transformation is

T=−ln⁡(1−U)λ.T=-\frac{\ln(1-U)}{\lambda}.

With U=0.80U=0.80 and λ=0.25\lambda=0.25 per year, T=−ln⁡(0.20)/0.25=6.4378T=-\ln(0.20)/0.25=6.4378 years. A Bernoulli event with probability pp can similarly be generated as I(U<p)I(U<p), while a categorical outcome is selected by locating UU within cumulative category probabilities.

Normal and other distribution generators

Normal draws may be produced by an inverse normal distribution function, the Box–Muller transformation, or specialised algorithms used by statistical libraries. Analysts should normally rely on a tested library implementation because accuracy in the extreme tails, numerical stability, and reproducibility can depend on the precise algorithm.

Different software versions may change the distribution-conversion algorithm even when the underlying uniform generator is unchanged. Reproducibility records should therefore identify both the base generator and the routine used to produce non-uniform variates.

Correlated random quantities

Independent uniform draws do not by themselves reproduce correlation among parameters or outcomes. For a multivariate normal vector with mean μ\boldsymbol\mu and covariance matrix Σ\boldsymbol\Sigma, correlation can be introduced through a matrix factor. One common construction is

Z=μ+Lε,LLT=Σ,ε∼N(0,I).\mathbf Z=\boldsymbol\mu+\mathbf L\boldsymbol\varepsilon, \qquad \mathbf L\mathbf L^{\mathsf T}=\boldsymbol\Sigma, \qquad \boldsymbol\varepsilon\sim N(\mathbf 0,\mathbf I).

The resulting components of Z\mathbf Z have the specified covariance structure. When normal draws are subsequently transformed to skewed marginal distributions, Pearson correlations may change, so copula choice and the scale on which dependence is specified must be documented.

Parameter uncertainty and event-level randomness

Random draws can represent different sources of uncertainty, and these sources should not be conflated. A probabilistic sensitivity analysis commonly draws one jointly distributed parameter set per outer iteration, whereas an individual-level simulation then draws event times and outcomes conditional on that set.

Parameter correlation belongs in the joint parameter distribution; correlation between repeated outcomes for one person belongs in the individual-level stochastic structure. Drawing a fresh parameter value for every person when the parameter is intended to be common to the population changes the estimand and usually understates shared uncertainty.

Streams, substreams, and parallel simulation

A stream is a controlled portion of a generator's sequence, and a substream is a reproducibly separated portion allocated to a particular task, replicate, strategy, or worker. Parallel simulations should use a generator with supported stream splitting, jump-ahead, or counter-based generation so that workers do not accidentally overlap or produce results that depend on scheduling order.

Setting worker seeds to seed + worker_number is not a general guarantee of independent streams. A defensible implementation records the generator family, stream-allocation rule, worker mapping, and any jump or counter settings.

Common random numbers

Common random numbers use matched stochastic draws when comparing alternative strategies so that much of the simulation noise cancels in the incremental result. If CA(r)C_A^{(r)} and CB(r)C_B^{(r)} are strategy costs in replication rr, pairing their draws can reduce the variance of CB(r)−CA(r)C_B^{(r)}-C_A^{(r)} when the paired outcomes are positively correlated.

Matching must preserve meaning: the draw used for a patient's baseline risk in one strategy should correspond to the same latent quantity in the comparator. Reusing one uniform value for distinct events merely to force correlation can bias results rather than reduce variance.

Variance-reduction methods

Antithetic sampling evaluates paired uniforms (U,1−U)(U,1-U), while stratification and Latin hypercube sampling distribute draws more evenly across the unit interval or hypercube. These methods can improve precision, but only if their implementation preserves every target marginal distribution and the intended dependence structure.

For an estimated mean Xˉ\bar X based on NN independent replications with sample standard deviation ss, the simulation standard error is approximately

SE⁡(Xˉ)=sN.\operatorname{SE}(\bar X)=\frac{s}{\sqrt N}.

Consequently, halving Monte Carlo error ordinarily requires approximately four times as many independent replications. Variance reduction can be more efficient than increasing NN, but its performance should be confirmed for the model's actual output.

Quasi-random sequences

Sobol and Halton sequences are low-discrepancy, deterministic point sets designed to fill a multidimensional unit cube more evenly than ordinary pseudorandom draws. They are therefore quasi-random sequences, not PRNG sequences, and their effectiveness depends on dimension ordering, sample size, scrambling, and the smoothness of the integrand.

Randomised scrambling can permit repeated estimates and uncertainty assessment while retaining much of the low-discrepancy benefit. Standard Monte Carlo error formulas should not be applied mechanically to one deterministic quasi-random run.

Use in health-economic simulation

In probabilistic sensitivity analysis, one joint parameter vector is usually generated for each iteration and applied consistently to all strategies. In microsimulation or discrete-event simulation, additional random draws determine individual characteristics, transition events, competing event times, resource use, and costs conditional on those parameters.

Nested simulations require deliberate control of both outer parameter streams and inner patient or event streams. A fixed seed makes a flawed model reproducible; it does not validate its distributions, dependence assumptions, event logic, or decision conclusions.

Competing events and draw consumption

For competing risks, a model may draw separate latent event times and select the earliest, or sample from a correctly derived joint mechanism. Independent uniforms are appropriate only when conditional independence is justified; shared frailty or other dependence requires an explicit correlated construction.

Draw order is part of reproducibility because adding a diagnostic draw early in a program can shift every later result in a stateful generator. Named or counter-based streams for distinct processes can reduce this fragility, and failed runs should not silently consume draws that alter subsequent replicates.

Reproducibility and audit trail

A seed alone is an incomplete audit record. A reproducible analysis should retain enough information to reconstruct both the sequence and its allocation throughout the model.

RecordWhy it matters
Generator algorithm and variantDefines the state transition and statistical properties
Software and library versionsDistribution transforms and defaults can change
Seed and, where needed, full stateRecreates the starting point or exact continuation
Stream and substream assignmentsShows how draws were separated across tasks and workers
Distribution parameterisationsPrevents scale-versus-rate and similar ambiguities
Draw-order rulesExplains how model processes consume random values
Parallel configurationMakes scheduling and worker allocation auditable

Published models should also preserve the code or configuration that maps streams to model processes. Replication checks should confirm that the same environment produces identical outputs when exact reproducibility is claimed.

Spreadsheet implementation

Spreadsheet functions such as RAND() are convenient for demonstrations and simple exploratory calculations. They are volatile, recalculate when the workbook changes, and generally do not provide the explicit seed, state, stream management, and version control expected for a robust auditable simulation.

For example, =--(RAND()<p) generates a Bernoulli indicator and =-LN(1-RAND())/lambda generates an exponential time under a rate parameterisation. Production work should use a controlled statistical environment or a purpose-built implementation when exact reruns, parallel streams, or regulated auditability are required.

Testing a generator and its implementation

Checks can examine marginal uniformity, empirical moments, serial correlations, repeated values, multidimensional patterns, and agreement between generated and target distributions. Formal batteries such as statistical randomness test suites can identify particular departures from expected behaviour, but passing them does not prove that a generator is random, independent for every use, or secure against prediction.

Cryptographic unpredictability is unnecessary for most ordinary health-economic simulations, but it is essential when draws protect secrets or face an adversary. Statistical simulation quality and cryptographic security are different requirements and should be assessed separately.

Practical workflow

A controlled random-number workflow makes simulation results easier to reproduce, compare, and audit. The following sequence is suitable for most health-economic modelling applications. It separates statistical design from implementation and verification:

  1. Define which uncertainties are parameters, patient heterogeneity, and stochastic events.
  2. Specify every target distribution, parameterisation, correlation, and conditional dependency.
  3. Select a well-tested generator with an adequate period and supported stream controls.
  4. Assign stable streams or counters to strategies, processes, replications, and parallel workers.
  5. Use validated library transforms rather than hand-written distribution algorithms where possible.
  6. Pair strategy draws deliberately when common random numbers are appropriate.
  7. Test generated samples and model outputs against theoretical and independently calculated expectations.
  8. Quantify Monte Carlo error separately from parameter uncertainty and decision uncertainty.
  9. Record algorithms, versions, seeds or states, stream mappings, draw order, and parallel settings.
  10. Verify exact reruns and sensitivity to alternative seeds before interpreting decision results.

Interpretation and limitations

Random number generation is an implementation mechanism, not a source of empirical evidence. Its purpose is to sample faithfully from distributions and dependencies that must themselves be justified by data, assumptions, and the model's decision context.

Finite samples always contain Monte Carlo noise, and different valid generators or seeds will generally produce different point estimates. Confidence in a stochastic analysis therefore requires adequate replication, reported simulation error, stable conclusions across controlled reruns, and transparent separation of numerical uncertainty from substantive model uncertainty.

Library

Publications

1
  • Journal article

    Microsimulation Modeling for Health Decision Sciences Using R: A Tutorial — Krijkamp, Alarid-Escudero, Enns, Jalal, Hunink & Pechlivanoglou, Vol. 38, No. 3 ed., 2018 (Medical Decision Making)

    The DARTH workgroup’s tutorial on implementing individual-level (microsimulation) models in R, including vectorisation techniques that dramatically reduce run time — the standard reference for patient-level simulation in R.

Frequently Asked Questions (6)

  • What is random number generation?

    The computational process of producing a sequence of numbers approximating true randomness, used to sample parameter values in probabilistic health economic models.

    Source: Press et al. 2007

  • How does random number generation drive sampling in a model?

    Every random draw a model makes, whether a patient's characteristic in a simulation or a parameter value in a probabilistic analysis, starts from a stream of numbers produced by a random number generator. These raw numbers, spread evenly between zero and one, are transformed to follow whichever distribution a quantity is meant to have, so the generator is the source from which all the model's randomness flows. Its behaviour therefore underlies every sampled result. Press and colleagues (2007) describe this mechanism.

    Source: Press et al. 2007

  • How does random number generation work?

    Random number generation typically uses a deterministic algorithm that, from a starting value, produces a long sequence of numbers appearing uniformly distributed and independent. These uniform random numbers are then transformed to follow whatever distributions are required, such as normal or beta, so that sampled parameter values have the intended distribution. The algorithm is chosen to have good statistical properties and a long period, so the generated numbers adequately mimic randomness for the simulation.

    Source: Press et al. 2007

  • Why is random number generation important in health economic modelling?

    Random number generation is important because probabilistic health economic models rely on sampling parameter values from distributions to represent uncertainty, and this sampling requires random numbers. In probabilistic sensitivity analysis, each iteration draws parameter values using generated random numbers, and the model is run many times to build a distribution of results. Without reliable random number generation, such analyses could not be performed, so it is a basic computational tool underpinning the handling of uncertainty in modelling.

    Source: Briggs, Claxton & Sculpher 2006

  • How does random number generation support probabilistic sensitivity analysis?

    In probabilistic sensitivity analysis, random number generation provides the draws that sample each uncertain parameter from its assigned distribution in every iteration, so that the model can be run repeatedly with different sampled inputs. The resulting distribution of costs and effects reflects the combined parameter uncertainty. Reliable generation, transforming uniform random numbers into the required distributions, ensures the samples are representative, so the analysis correctly propagates uncertainty to the cost-effectiveness results and supports outputs such as acceptability curves.

    Source: Briggs, Claxton & Sculpher 2006

  • What ensures the quality of random number generation?

    The quality of random number generation depends on the generator having good statistical properties, producing numbers that are uniformly distributed, independent, and free of detectable patterns, and a long period before repeating. Poor generators can introduce correlations that bias simulations, so well-tested algorithms are used. The transformation of uniform numbers into required distributions must also be correct. Ensuring these properties matters because large simulations draw many numbers, and defects would distort the sampled inputs and hence the results.

    Source: Metropolis & Ulam 1949

Trust Record

Verified by Dr Darrin Baines

British health economist

Professional identity: darrinbaines.org

Verification date: 25 Sep 2026

Content version: 1.0.0

Canonical Identity

Term code
HE-EM-MS-008

Stable URI · Machine-readable · Resolvable · CC BY 4.0