Numpy random seed valid for entire jupyter notebook

后端 未结 2 1630
[愿得一人]
[愿得一人] 2021-01-11 13:04

I\'m using functions from numpy.random on a Jupyter Lab notebook and I\'m trying to set the seed using numpy.random.seed(333). This works as expect

2条回答
  •  渐次进展
    2021-01-11 13:45

    Because you're repeatedly calling randint, it generates different numbers each time. It's important to note that seed does not make the function consistently return the same number, but rather makes it such that the same sequence of numbers will be produced if you repeatedly run randint the same amount of times. Therefore, you're getting the same sequence of numbers every time you re-run the random.randint, rather than it always producing the same number.

    Re-seeding in that specific cell, before each random.randint call, should work, if you want the same random number every single time. Otherwise, you can expect to consistently get the same sequence of numbers, but not to get the same number every time.

提交回复
热议问题