This section briefly outlines efficient algorithms for generating random variates for some probability distributions commonly used in hydrosystems engineering and analysis.
A normal random variable with a mean цx and standard deviation ox, denoted as X ~ N(p. x, ox), has a PDF given in Eq. (2.58). The relationship between X and the standardized normal variable Z is
X = ^x + OxZ (6.11)
in which Z is the standard normal random variable having a mean 0 and unit standard deviation, denoted as Z ~ N(0,1). Based on Eq. (6.11), normal random variates with a specified mean and standard deviation can be generated from standard normal variates. Herein, three simple algorithms for generating standard normal variates are described.
Box-Muller algorithm. The algorithm (Box and Muller, 1958) produces a pair of independent N(0,1) variates as
z1 = v/-2ln(u1) cos(2n u2)
______________ (6.12)
Z2 = /-2ln(U2) sin(2nU2)
in which u1 and u2 are independent uniform variates from U(0,1). The algorithm involves the following steps:
1. Generate two independent uniform random variates u1 and u2 from U(0, 1).
2. Compute z1 and z2 simultaneously using u1 and u2 according to Eq. (6.12).
Marsagalia-Bray algorithm. Marsagalia and Bray (1964) proposed an alternative algorithm that avoids using trigonometric evaluations. In their algorithm, two independent uniform random variates u1 and u2 are produced to evaluate the following three expressions:
V1 = 2U1 — 1
V2 = 2U2 — 1 (6.13)
R = V1 + V 22
If R > 1, the pair (u1, u2) is rejected from further consideration, and a new pair (u1, u2) is generated. For the accepted pair, the corresponding standard
normal variates are computed by