Euler_Salter
Euler_Salter

Reputation: 3571

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).

Upvotes: 1

Views: 250

Answers (1)

joostblack
joostblack

Reputation: 2535

You can use rng.normal(10) instead.

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

Upvotes: 4

Related Questions