Generating random data
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 within the range . Ideally, these numbers should be selected uniformly, so that if we draw a large number of these numbers, they are distributed roughly evenly across the range .
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.
We also import the Matplotlib pyplot
module under the plt
alias.