rDiscrete

rDiscrete(*args)

Realization of a bounded integral discrete distribution.

Parameters
probabilitiessequence of float

The probabilities of the discrete distribution p_k=\Prob{X=k}, where p_k\in[0,1] and \sum_{k=1}^n p_k=1.

sizeint

The number of realizations to generate.

Returns
realizationsint or Indices

The realizations of the discrete disctribution.

Notes

This method implements the alias method as described in [devroye1986], Chapter 3. It has an optimal space complexity of \cO(n) and runtime CPU complexity of \cO(1).

Examples

>>> import openturns as ot
>>> ot.RandomGenerator.SetSeed(0)
>>> r = ot.DistFunc.rDiscrete([0.2, 0.3, 0.5])
>>> r = ot.DistFunc.rDiscrete([0.2, 0.3, 0.5], 10)