randomLogarithmic¶
Generates pseudorandom numbers from a logarithmic distribution.
Synopsis¶
randomLogarithmic (nRandom, a)
Required Arguments¶
- int
nRandom
(Input) - Number of random numbers to generate.
- float
a
(Input) - Parameter of the logarithmic distribution. Parameter
a
must be positive and less than 1.0.
Return Value¶
An integer array of length nRandom
containing the random logarithmic
deviates.
Description¶
Function randomLogarithmic
generates pseudorandom numbers from a
logarithmic distribution with parameter a
. The probability function is
for \(x=1,2,3,\ldots\), and \(0<a<1\)
The methods used are described by Kemp (1981) and depend on the value of a. If a is less than 0.95, Kemp’s algorithm LS, which is a “chop-down” variant of an inverse CDF technique, is used. Otherwise, Kemp’s algorithm LK, which gives special treatment to the highly probable values of 1 and 2 is used.
Example¶
In this example, randomLogarithmic
generates five pseudorandom
logarithmic deviates from a logarithmic distribution with parameter a equal
to 0.3.
from numpy import *
from pyimsl.stat.randomLogarithmic import randomLogarithmic
from pyimsl.stat.randomSeedSet import randomSeedSet
from pyimsl.stat.writeMatrix import writeMatrix
n_random = 5
a = 0.3
randomSeedSet(123457)
ir = randomLogarithmic(n_random, a)
writeMatrix("Logarithmic random deviates:", ir,
noColLabels=True)
Output¶
Logarithmic random deviates:
2 1 1 1 2