How to generate random numbers in Python with NumPy
howtogeek.com·17h
Flag this post

Summary

  • Create an rng object with np.random.default_rng(), you can seed it for reproducible results.
  • You can draw samples from probability distributions, including from the binomial and normal distributions.
  • You can shuffle arrays in place with rng.shuffle().

Whether you’re simulating probability distributions or just want a random number, it’s easy to do with Python’s NumPy library.

Creating the random number generator

To be able to generate random numbers with NumPy, you need to create the random number generator. You can do this after importing the library with a simple command:

import numpy as nprng = np.random.default_rng()

Don’t forget…

Similar Posts

Loading similar posts...