# How to set seed for random drawings with Numpy? [closed]

I'm trying to set the seed for a few lines of code in a jupyter notebook.

However, when I tried running numpy.random.seed(0) in the initial cell, in the later cells the random generator was not 'seeded'. I had to write a set seed in all the cells where I was running the random draws... Why is that? Is there a way to avoid having to write the same thing in every cell where I have a random draw?

Also, I checked the numpy documentation and it seems that numpy.random.seed() is not the best practice. I don't understand the example given there... How would I go about, according to the best practices shown in the example, in order to do something similar to numpy.random.seed(constant)?

• This seems like an artifact of running in Jupyter. If you put all of that in a .py file that you run from the command line, the seeding will remain throughout the entirety of the script. – Dave Nov 18 '20 at 11:15
• I think asking this in the main site of stack overflow will give you an answer much faster – Gulzar Nov 18 '20 at 18:19
• Is this the same issue: stackoverflow.com/questions/51424857/…? – Burger Nov 18 '20 at 19:56
• @Burger, yes, it is. Thanks ;) – An old man in the sea. Nov 22 '20 at 9:05
• @Gulzar thanks ;) – An old man in the sea. Nov 22 '20 at 9:06