RDNORM and RDUNIF: Generating Random Numbers

How to:

Available Languages: reporting, Maintain

The RDNORM and RDUNIF functions generate random numbers:


Top of page

x
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