Home >Backend Development >Python Tutorial >Why do I get different random numbers using the same seed?
I am using a numpy random number generator with the following mwe:
import numpy as np np.random.seed(40) print(np.random.randint(-3, 4)) rng = np.random.default_rng(seed=40) print(rng.integers(-3, 4))
Output:
3 0
Why is the output different?
numpy.random.randint
and numpy.random.seed
use the old random API, which The underlying implementation is completely different. numpy.random.default_rng
Create a Generator object, this is the new API.
These two APIs are actually two completely independent RNG libraries that happen to be in the same namespace. Even with the same seed, the output won't match.
The above is the detailed content of Why do I get different random numbers using the same seed?. For more information, please follow other related articles on the PHP Chinese website!