RDNORM and RDUNIF: Generating Random Numbers

How to:

Available Languages: reporting, Maintain

The RDNORM and RDUNIF functions generate random numbers:

  • RDNORM generates double-precision random numbers normally distributed with an arithmetic mean of 0 and a standard deviation of 1.

    If RDNORM generates a large set of numbers (between 1 and 32768), they have the following properties:

    • The numbers lie roughly on a bell curve, as shown in the following figure. The bell curve is highest at the 0 mark, meaning that there are more numbers closer to 0 than farther away.
    • The average of the numbers is close to 0.
    • The numbers can be any size, but most are between 3 and -3.
  • RDUNIF generates double-precision random numbers uniformly distributed between 0 and 1 (that is, any random number it generates has an equal probability of being anywhere between 0 and 1).

Syntax: How to Generate Random Numbers

{RDNORM|RDUNIF}(output)

where:

RDNORM

Generates double-precision random numbers normally distributed with an arithmetic mean of 0 and a standard deviation of 1.

RDUNIF

Generates double-precision random numbers uniformly distributed between 0 and 1.

output

Double-precision

Is the name of the field that contains the result, or the format of the output value enclosed in single quotation marks.

Example: Generating Random Numbers

RDNORM assigns random numbers and stores them in RAND. These numbers are then used to randomly choose five employee records identified by the values in the LAST NAME and FIRST NAME fields.

DEFINE FILE EMPLOYEE
RAND/D12.2 WITH LAST_NAME = RDNORM(RAND);END
TABLE FILE EMPLOYEE
PRINT LAST_NAME AND FIRST_NAME
BY HIGHEST 5 RAND
END

The request produces output similar to the following:

RAND  LAST_NAME        FIRST_NAME 
----  ---------        ---------- 
 .65  CROSS            BARBARA 
 .20  BANNING          JOHN 
 .19  IRVING           JOAN 
 .00  BLACKWOOD        ROSEMARIE 
-.14  GREENSPAN        MARY

WebFOCUS

Feedback