Many tasks involve generating large quantities of random numbers, which, in their most basic form, are either integers or floating-point numbers (double precision) lying in the range 0 ≤ x < 1. Ideally, these numbers should be selected uniformly, so that if we draw a large quantity of such numbers, they should be distributed roughly evenly across the range 0 ≤ x < 1.
In this recipe, we will see how to generate large quantities of random integers and floating-point numbers using NumPy, and show the distribution of these numbers using a histogram.
Getting ready
Before we start, we need to import the default_rng routine from the NumPy random module and create an instance of the default random number generator to use in the recipe:
from numpy.random import default_rng
rng = default_rng(12345) # changing seed for reproducibility
We have discussed this process in the Selecting items at random recipe.
...