RNUND
Generates pseudorandom numbers from a discrete uniform distribution.
Required Arguments
K — Parameter of the discrete uniform distribution. (Input)
The integers 1, 2, …, K occur with equal probability. K must be positive.
IR — Vector of length NR containing the random discrete uniform deviates. (Output)
Optional Arguments
NR — Number of random numbers to generate. (Input)
Default: NR = size (IR,1).
FORTRAN 90 Interface
Generic: CALL RNUND (K, IR [, …])
Specific: The specific interface name is S_RNUND.
FORTRAN 77 Interface
Single: CALL RNUND (NR, K, IR)
Description
Routine RNUND generates pseudorandom numbers from a discrete uniform distribution over the integers 1, 2, …, K. A random integer is generated by multiplying K by a uniform (0, 1) random number, adding 1.0, and truncating the result to an integer. This, of course, is equivalent to sampling with replacement from a finite population of size K. To do the equivalent of sampling without replacement, the routine RNSRI can be used.
Comments
The routine RNSET can be used to initialize the seed of the random number generator. The routine RNOPT can be used to select the form of the generator.
Example
In this example, RNUND is used to generate five pseudorandom deviates from a discrete uniform distribution over the integers from 1 to 6.
USE RNUND_INT
USE UMACH_INT
USE RNSET_INT
IMPLICIT NONE
INTEGER IR(5), ISEED, K, NOUT, NR
!
CALL UMACH (2, NOUT)
K = 6
NR = 5
ISEED = 123457
CALL RNSET (ISEED)
CALL RNUND (K, IR)
WRITE (NOUT,99999) IR
99999 FORMAT (' Discrete uniform (1,6) random deviates: ', 5I7)
END
Output
Discrete uniform (1,6) random deviates: 6 2 5 4 6