randomUniformDiscrete¶
Generates pseudorandom numbers from a discrete uniform distribution.
Synopsis¶
randomUniformDiscrete (nRandom, k)
Required Arguments¶
- int
nRandom(Input) - Number of random numbers to generate.
- int
k(Input) - Parameter of the discrete uniform distribution. The integers 1, 2, …,
koccur with equal probability. Parameterkmust be positive.
Return Value¶
An integer array of length nRandom containing the random discrete
uniform deviates.
Description¶
Function randomUniformDiscrete generates pseudorandom numbers from a
uniform discrete 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.
Example¶
In this example, randomUniformDiscrete generates five pseudorandom
discrete uniform deviates from a discrete uniform distribution over the
integers 1 to 6.
from numpy import *
from pyimsl.stat.randomUniformDiscrete import randomUniformDiscrete
from pyimsl.stat.randomSeedSet import randomSeedSet
from pyimsl.stat.writeMatrix import writeMatrix
n_random = 5
k = 6
randomSeedSet(123457)
ir = randomUniformDiscrete(n_random, k)
writeMatrix("Discrete Uniform (1, 6) random deviates:", ir,
noColLabels=True, writeFormat="%5i")
Output¶
Discrete Uniform (1, 6) random deviates:
6 2 5 4 6