Investment Studio > Expressions > Functions > Math & Trig > RAND

float rand()

Returns an evenly distributed random number in the range [0, 1[.

A new random number is returned every time the expression is calculated.

To generate an evenly distributed random real number between A and B, use A + rand() * (B - A).

To generate random real numbers with standard normal distribution (see normsdist), use the Box-Müller method: given two independent, evenly distributed random numbers r1 and r2 between 0 and 1, the numbers s1 and s2 given by

s1 = sqrt(-2 * ln(r1)) * cos(2 * pi * r2)

s2 = sqrt(-2 * ln(r1)) * sin(2 * pi * r2)

are independent with standard normal distribution. See the example in kurt for a vector implementation.

Alternatively, use the central limit theorem: compute the sum S of 12 independent, evenly distributed random numbers between 0 and 1, then calculate

s = (S - 6) s + m

to get a random number s with approximately normal distribution, standard deviation s and mean m.

Example

=rand() * 10

returns a random real number greater than or equal to 0 but less than 10.

See also randbetween.