Random numbers are important resources for scientific applications, education, game development and visualization.
The standard RTL function random generates random numbers that fulfill a uniform distribution. In order to create random numbers of other distributions special algorithms are necessary.
Normal (Gaussian) Distribution
One of the more common algorithms to produce normally distributed random numbers from uniformly distributed random numbers is the Box-Müller approach. The following function calculates Gaussian-distributed random numbers:
function rnorm (mean, sd: real): real;
{Calculates Gaußian random numbers according to the Box-Müller approach}
var
u1, u2: real;
begin
u1 := random;
u2 := random;
rnorm := mean * abs(1 + sqrt(-2 * (ln(u1))) * cos(2 * pi * u2) * sd);
end;