Generator.geometric(self, p, size=None)

Draws samples from a geometric distribution.

Bernoulli trials are experiments with one of two outcomes: success or failure (an example of such an experiment is flipping a coin). The geometric distribution models the number of trials that must be run in order to achieve success. It is therefore supported on the positive integers, k = 1, 2, ....

The probability mass function of the geometric distribution is

f(k) = (1 - p)^{k - 1} p

where p is the probability of success of an individual trial.


The probability of success of an individual trial.

sizeint or tuple of ints, optional

Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn.


Drawn samples from the parameterized geometric distribution.


  • If p is neither a scalar nor None : NotImplementedError occurs.


Draw ten thousand values from the geometric distribution, with the probability of an individual success equal to 0.35:

>>> import nlcpy as vp
>>> z = vp.random.default_rng().geometric(p=0.35, size=10000)

How many trials succeeded after a single run?

>>> vp.sum(z == 1) / 10000.   
array(0.3453)  # random