ran

Date:

02-06-2023

NAME

_ranf, RANF, RANGET, RANSET - Compute pseudo-random numbers

SYNOPSIS

C

#include <intrinsics.h>

double _ranf(void);

Fortran

RANF()
RANGET ([[I=]i])
RANSET ([K=]k)

STANDARDS

C extensions

Fortran extension

DESCRIPTION

The _ranf and RANF functions return a pseudo-random floating-point number in the range of 0.0 < x < 1.0. Because _ranf is a C intrinsic function, no externally visible library function is available for it.

RANGET returns a seed from the random number seed table. It is an intrinsic function.

RANSET establishes a seed in the random number seed table. It is an intrinsic function.

NOTES

RANF obtains the first or next in a series of pseudorandom numbers. Parenthesis are required, that is: var = RANF(). If an argument is supplied, it is ignored.

RANGET obtains a seed. This routine must be used as a function, not as a subroutine. RANGET has an optional integer argument. If present, the argument is neither referenced nor defined. The argument for RANGET is as follows:

i

An optional INTEGER(KIND=8) variable.

RANSET establishes a seed by using the lower 48 bits of the argument. The result type is typeless. RANSET requires an argument. If a zero argument is supplied, the seed is reset to an initial default value. When the seed of the random number generator is reset, RANSET does not store the supplied argument as the first value in the buffer of the random number seeds. The lower 48 bits of the argument supplied are used as the random-number seed. The rightmost bit is always set to 1. The RANSET argument is:

k

Any nonzero KIND=8 integer, real, or Boolean argument.

The names of these intrinsics cannot be passed as arguments.

NOTES

In Fortran, the period of RANF() is 2**46. If you need to insure that two random number ranges do not overlap, you can determine this empirically by generating the two sets of numbers and comparing them against one another, and also against themselves, for an overlap. It should be noted, however, that when using RANSET to set the random number seed, the algorithm used always rounds up even-numbered seeds to the nearest odd-numbered seed (that is, the right most bit is always set to one). Some adjacent pairs of seeds will generate exactly the same set of random numbers. For example, seeds 4 and 5 will generate the same set of random numbers.

NOTES

In Fortran, the random number generator uses static memory storage for the random number seed table, so the RANF, RANSET, and RANGET functions must be protected (locked) when called from a multitasked program.

RANF generates a set of random numbers such that each random number depends on the previous random number for its value. Thus, depending on the order in which the tasks calling RANF execute, a different set of random numbers will be returned to each task. It cannot be guaranteed that each task will get a distinct and reproducible set of random number values.

RETURN VALUES

The _ranf and RANF functions return a 64-bit floating-point number in the range 0.0 < x < 1.0.

RANGET returns a 64-bit INTEGER result.

RANSET returns a 64-bit typeless result.

EXAMPLES

Returning and establishing seeds:

INTEGER ISEED, DUMMY, IVALUE
REAL RANDOM(10)
...
DO I=1,10
   RANDOM(I)=RANF()
END DO

ISEED=RANGET(IVALUE)

DUMMY=RANSET(IVALUE)

SEE ALSO

random_number(3i), random_seed(3i)

For a complete list of C intrinsic functions , see the Cray C and C++ Reference Manual