ran(3I)
_ranf, RAN, RANF, RANGET, RANSET - Computes pseudo-random numbers
As shipped in IRIX 6.5.19. Last changed in IRIX 6.5.19.
NAME _ranf, RAN, RANF, RANGET, RANSET - Computes pseudo-random numbers SYNOPSIS C/C++: #include <intrinsics.h> double _ranf(void); Fortran: RAN ([I=]i) RANF() RANDU ([I1=]i1, [I2=]i2, [X=]x) RANGET ([I=]i) RANSET ([K=]k) STANDARDS C/C++ extension Fortran extension DESCRIPTION _ranf and RAND return a pseudo-random floating-point number in the range of 0.0 < x < 1.0. Because _ranf is a C/C++ intrinsic function, no externally visible library function is available for it. RAN returns the next number from a sequence of pseudorandom numbers of uniform distribution over the range 0 to 1. It is an intrinsic function, but because RAN is not a pure function, it cannot be referenced inside of a FORALL construct. RANDU computes a pseudorandom number as a single-precision value. It is an intrinsic subroutine. 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. ARGUMENTS RAN accepts the following argument: i Must be an integer (KIND=4) variable or array element. This is the seed. Initially, i should 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, but it should be initialized with different values on separate runs to obtain different random numbers. 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. RANDU accepts the following arguments: i1, i2 Must be integer (KIND=2) variables or array elements that contain the seed for computing the random number. These values are updated during the computation so that they contain the updated seed. x Must be a real (KIND=4) variable or array element. This argument holds the return value. RANGET obtains a seed. It is recommended that this routine be used as a function because it is not considered intrinsic when called as a subroutine. RANGET has an optional integer argument. If present, the argument is set to the seed. The argument for RANGET is as follows: i An integer of default kind (KIND=8). If present, RANGET returns the seed in i. RANSET establishes a seed by using the lower 48 bits of the argument. The result type is typeless. If no argument or 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. If an argument is supplied, the lower 48 bits are used as the random-number seed. The rightmost bit is always set to 1. The RANSET arguments are as follows: k An optional integer, real, or Boolean argument of default kind (KIND=8). The range of argument k is |k| < inf, where inf is approximately 10**308. j An optional integer argument that, if specified, is used as a count for skipping the first section of sequential random numbers. You can use this to create a complete sequence of random numbers while running on many PEs by breaking up the sequence into subsequences and using RANSET() to get each subsequence started in the correct location. The names of these intrinsics cannot be passed as arguments. On IRIX systems, RANF uses a 64-bit linear congruential generator with a default seed of 1274321477413155 (octal). RANF REPEAT PERIOD 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. RANF AND MULTITASKING 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 _ranf and RANF 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. RAN returns a real (KIND=4) result. This is a floating-point number that is uniformly distributed in the range 0.0 <= result < 1.0. It is set equal to the value associated with the argument i. RANDU returns the result in x, which must be of type real (KIND=4). The result value is a pseudorandom number in the range 0.0 to 1.0. The algorithm for computing the random number value is based on the values for i1 and i2. If i1 = 0 and i2 = 0, the generator base is set as follows: x (n + 1) = 2**16 + 3 Otherwise, the generator base is set as follows: x (n + 1) = (2**16 + 3) * x (n) mod 2**32 The generator base, x (n + 1), is stored in i1, i2. The result is x (n + 1) scaled to a real value y (n + 1), for 0.0 <= y (n + 1) < 1. EXAMPLES Example 1. The following example is written in Fortran: DO 10 I=1,10 10 RANDOM(I)=RANF() iseed=RANGET(ivalue) dummy=RANSET(ivalue) Example 2. RAN has the value 4.8220158E-05 for RAN(I) when I=3. Example 3. Consider the following: REAL X INTEGER(2) I, J ... CALL RANDU (I, J, X) If I and J are values 4 and 6, X stores the value 5.4932479E-04. SEE ALSO RANDOM_NUMBER(3I), RANDOM_SEED(3I)