randomPoisson

../../_images/OpenMp_27.png

Generates pseudorandom numbers from a Poisson distribution.

Synopsis

randomPoisson (nRandom, theta)

Required Arguments

int nRandom (Input)
Number of random numbers to generate.
float theta (Input)
Mean of the Poisson distribution. Argument theta must be positive.

Return Value

An array of length nRandom containing the random Poisson deviates.

Description

Function randomPoisson generates pseudorandom numbers from a Poisson distribution with positive mean theta. The probability function (with θ = theta) is

\[f(x) = \left(e^{-\theta} \theta^x\right) / x! \phantom{...} \text{for } x = 0,1,2, \ldots\]

If theta is less than 15, randomPoisson uses an inverse CDF method; otherwise, the PTPE method of Schmeiser and Kachitvichyanukul (1981) (see also Schmeiser 1983) is used. The PTPE method uses a composition of four regions, a triangle, a parallelogram, and two negative exponentials. In each region except the triangle, acceptance/rejection is used. The execution time of the method is essentially insensitive to the mean of the Poisson.

Function randomSeedSet can be used to initialize the seed of the random number generator; function randomOption can be used to select the form of the generator.

Example

In this example, randomPoisson is used to generate five pseudorandom deviates from a Poisson distribution with mean equal to 0.5.

from numpy import *
from pyimsl.stat.randomPoisson import randomPoisson
from pyimsl.stat.randomSeedSet import randomSeedSet
from pyimsl.stat.writeMatrix import writeMatrix

n_random = 5
theta = 0.5
randomSeedSet(123457)
ir = randomPoisson(n_random, theta)
writeMatrix("Poisson(0.5) random deviates:", ir,
            noColLabels=True, writeFormat="%5i")

Output

 
  Poisson(0.5) random deviates:
    2      0      1      0      1