Python - passing random seed (generator) to `randn()`

I was reading this blog post and they suggest that rather than setting the random seed for the whole document

np.random.seed(1234)
x = np.random.randn(100)

One should use a generator, which can be created as such

rng = np.random.default_rng(1234)

In the post they use the example of rng.rand(10) which works fine. I need to use randn() however and it doesn't work if you use rng.randn(10).


Solution 1:

You can use rng.normal(10) instead.

The normal method is the equivalent of randn but using a random generator instance.