Home > Software design >  What does random.seed([list of int]) do?
What does random.seed([list of int]) do?

Time:05-22

I know what random.seed(int) does, like below:

random.seed(10)

But I saw a code which uses random.seed([list of int]), like below:

random.seed([1, 2, 1000])

What is the difference between passing a list and int to random.seed ?

CodePudding user response:

The answer is basically in the comments, but putting it together: it appears the code you found imports random from numpy, instead of importing the standard Python random module:

from numpy import random

random.seed([1, 2, 1000])

Not recommended, to avoid exactly the confusion you're running into.

numpy can use a 1d array of integers as a seed (presumably because it uses a different pseudo-random function than Python itself to generate 'random' numbers, which can use a more complex seed), as described in the documentation for numpy.RandomState

  • Related