Generate Geometrically Distributed Data in Python

Your goal

You need to randomly generate geometrically distributed data in Python.

Step-by-step tutorial

We will use the geometric random number generator from numpy.random.default_rng.

>>> from numpy.random import default_rng
>>> rng = default_rng()
>>> data = data = rng.geometric(0.3, 5000)
>>> data
array([5, 1, 3, ..., 3, 1, 5])

Here's a histogram for the data:

>>> plt.hist(data, bins=range(30))
Histogram of geometrically distributed data
Histogram of geometrically distributed data