rDiscrete

rDiscrete(*args)

Realization of a bounded integral discrete distribution.

Parameters:
probabilitiessequence of float, (p_1, \dots, p_n)\in[0,1] with \sum_{k=1}^n p_k=1,

The probabilities of the discrete distribution.

sizeint

The number of realizations to generate.

Returns:
realizationsint or Indices

The realizations of the distribution.

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)