RAN

RAN can be used as an intrinsic function or as a run-time routine.


RAN Intrinsic Function

Nonelemental Intrinsic Function (Specific): Returns the next number from a sequence of pseudorandom numbers of uniform distribution over the range 0 to 1.

This is a specific function that has no generic function associated with it. It must not be passed as an actual argument. It is not a pure function, so it cannot be referenced inside a FORALL construct.

Syntax

result = RAN (i)

i
(Input) Must be an INTEGER(4) variable or array element.
It should initially be set to a large, odd integer value. The RAN function stores a value in the argument that is later used to calculate the next random number.

There are no restrictions on the seed, although it should be initialized with different values on separate runs to obtain different random numbers.

Results:

The result type is REAL(4). The result is a floating-point number that is uniformly distributed in the range between 0.0 inclusive and 1.0 exclusive. It is set equal to the value associated with the argument i.

Compatibility

CONSOLE STANDARD GRAPHICS QUICKWIN GRAPHICS WINDOWS DLL LIB

See Also: RANDOM, RANDOM_NUMBER

Example

In RAN (I), if variable I has the value 3, RAN has the value 4.8220158E-05.


RAN Run-Time Routine

Run-Time Function: Returns a pseudorandom number greater than or equal to zero and less than one from the uniform distribution.

Syntax

result = RAN (iseed)

iseed
(Input) INTEGER(4). Seed for the random number generator.

Results:

The result is of type REAL(4). The result is a pseudorandom number, x, where 0 <= x < 1.

To ensure different random values for each run of a program, use different initial values of iseed (for example, use a reading from the system clock). The argument iseed should initially be set to a large, odd integer value. RAN stores a value in the argument iseed that it later uses to calculate the next random number.

The procedures RANDOM, RAN, and RANDOM_NUMBER, and the portability functions DRAND, DRANDM, RAND, IRANDM, RAND, and RANDOM use the same algorithms and thus return the same answers. They are all compatible and can be used interchangeably. (The algortihm used is a "Prime Modulus M Multiplicative Linear Congruential Generator," a modified version of the random number generator by Park and Miller in "Random Number Generators: Good Ones Are Hard to Find," CACM, October 1988, Vol. 31, No. 10.)

Compatibility

CONSOLE STANDARD GRAPHICS QUICKWIN GRAPHICS WINDOWS DLL LIB

See Also: RANDOM, RANDOM_NUMBER

Example

 INTEGER(4) iseed
 REAL(4) rnd
 iseed = 425001
 rnd = RAN(iseed)