One method applies inverse transform sampling to the standard normal cumulative distribution function: , followed by for mean and standard deviation . Numerical approximations to are needed, and the endpoints must be avoided.
A convenient alternative is the Box-Muller transform. From independent uniforms set
The radial probability density function is for , and the angle is independently uniform on . Dividing their joint density by the polar-coordinate Jacobian determinant gives
Thus the outputs are independent standard normal distribution draws. Apply to obtain other normal means and variances. With finite pseudorandom number generators, this is an approximation to the ideal independent-uniform model; poor dependence in the input stream is not cured by the transform.
One route is inverse transform sampling: if is the standard normal cumulative distribution function, then has the normal distribution with mean and variance .
Alternatively the Box-Muller transform uses two independent uniform inputs :
To verify this, set and . The radial density is for , and the angle is independent and uniform. Their joint density is . Changing to Cartesian coordinates divides by the Jacobian determinant , giving
This factors into two standard normal densities, proving both normality and independence. Then provides the required means and variances. Implementations must avoid the zero input to the logarithm; ideal continuous uniforms hit it with probability zero.
All the following distributions are conditional on the point lying in the unit disk. Initially the joint probability density of is on the square. The disk has area , so the conditioning event has probability . Dividing by this probability gives the constant conditional density on the disk, proving its uniform distribution there.
The polar coordinates have Jacobian determinant . Consequently
Integrating the joint probability density gives and . Since the joint density equals the product of these marginal densities on a product support, and are independent. In particular has the uniform distribution on .
The second change of variables preserves the angle and changes the radius to
The event has probability zero, so arbitrary definitions at that point have no effect on the distribution. For , monotonicity of the logarithm gives
Since is a function of , it remains independent of the uniform angle. Hence the new joint probability density is
Finally, has polar Jacobian determinant . Dividing the preceding density by gives the Cartesian joint probability density
This factors into two standard normal distribution densities on . Thus and are independent, each with mean zero and variance one. This derivation is the radial form of the Box-Muller transform.
The first algorithm uses independent normal distributions: generate with law and return
For example, the Box-Muller transform generates two such normal variates from independent uniforms:
To verify this, has density and is an independent uniform angle. Converting the resulting polar density to Cartesian coordinates gives , which factors into two independent normal distributions. Independent pairs therefore give the required sum, discarding a spare coordinate when is odd. Its moment-generating function is , that of the chi-squared distribution.
A genuinely different algorithm uses exponential-envelope rejection sampling for a chi-squared variable. Put . The target and proposal probability density functions are
For , differentiating gives , so the maximum is at . The envelope constant and normalized density ratio are
They remain valid at , where and . Repeatedly draw fresh independent , put , and accept when
The right side is nonpositive by , so this is a legitimate acceptance probability. The joint probability of proposing and accepting in is ; conditional on acceptance the density is exactly . This proves the rejection sampling algorithm, rather than only identifying the target law.
For I prefer the second method: it reduces to a single exponential draw with no rejection. The first method is simple and attractive when normal draws are already available or is small. For larger , the second method avoids generating normals: its acceptance probability is , asymptotic to by Stirling's formula. Its expected number of proposals grows like , rather than the linear number of normal draws in the first method. Both are exact ideal-uniform algorithms; actual runtime also depends on the implementation.
For the Box-Muller transform, draw independent from the uniform distribution on and set
The radial density is for , with an independent uniform angle. The polar-to-Cartesian Jacobian determinant is , so the joint density of is
This factorization proves that both outputs have the standard normal distribution and are independent. Repeating the Box-Muller transform with fresh independent uniform pairs gives independent normal outputs; discard one extra output if the desired sample size is odd.
For the prescribed binary probabilities, generate independent standard normal values in this way and use
The standard normal distribution function gives , and independence is preserved because each threshold uses a different independent normal value.
For the probit regression posterior, introduce latent variables
Given , these are independent variables, and normal symmetry gives . Thus this data augmentation has exactly the observed binary likelihood. With the specified normal prior distribution, the augmented joint posterior is proportional to
The latent-normal Gibbs sampler for probit regression alternates two blocks. First, given the current , draw each independently from its truncated normal distribution, namely restricted to the sign fixed by . One exact method is to use the Box-Muller transform for , form , and reject until the sign is correct. The probability of success is positive at every finite parameter value, so the method is valid, although it can be slow for a rare sign.
For direct sign-truncated normal sampling, let , and draw . An inverse transform sampling implementation is
Use suitable tail or survival-function evaluations when floating-point probabilities approach zero or one; the rejection construction remains a valid alternative.
Second, completing the square in yields its full conditional distribution:
Generate a fresh standard normal value by the Box-Muller transform, multiply by the conditional standard deviation, and add the conditional mean. Start from any finite , alternate these steps, discard an initial transient and use the retained values to approximate its posterior distribution. These are dependent Markov chain Monte Carlo samples, rather than independent posterior draws. Each block is an exact Gibbs sampling update for the augmented posterior, whose marginal in is the requested posterior.
Generate independent and use the Box-Muller transform
For , , so its density is on . The angle is uniform on and independent of . Dividing the joint radial-angular density by the polar-coordinate Jacobian gives
Thus both outputs are independent and have the standard normal distribution. Independent pairs of uniforms give further independent normal observations. The null event is excluded in implementation so the logarithm is finite.
Recognize the integrand as a Gaussian scale mixture. If has the unit Rayleigh distribution and is an independent standard normal distribution variable, then the conditional density of given is . Multiplying by the radius density gives
Thus use for the independent radius and for the normal output of the Box-Muller transform:
The mixture argument also proves that integrates to one, by the Tonelli theorem. As a check, is exponential of rate , so the characteristic function of is . This is the Rayleigh-normal scale mixture, with Laplace distribution density .
The Box-Muller transform uses independent uniforms to set
The radius has the unit Rayleigh distribution, with density for , and the angle is independently uniform on . Their joint density is . The Cartesian change of variables has absolute Jacobian determinant , so the joint density of is
The factorization proves that the outputs are independent random variables, each with a standard normal distribution.
Draw independent uniformly on , and set
This is the Box-Muller transform. The endpoint has probability zero; an implementation should avoid evaluating its logarithm.
For , , so has density . It is independent of the angle, which has a uniform distribution on , and their joint density is . Transforming to Cartesian coordinates divides by the polar-coordinate Jacobian , yielding
Thus the outputs are independent random variables with the standard normal distribution, proving the algorithm.