Random Numbers
Use a Generator from default_rng with a seed for repeatable results. It offers random, integers, normal and choice.
Example
import numpy as np
rng = np.random.default_rng(42)
x = rng.integers(0, 10, size=5)
print(x.shape, x.dtype.kind)
y = rng.random(3)
print(y.shape, bool((y >= 0).all() and (y < 1).all()))Result
(5,) i (3,) True
Exercise
Create a generator.
np.random.(42)
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.