I did some digging around. Here’s what I found from the NumPy documentation:

Seed the generator.

This method is called when `RandomState`

is initialized. It can be called again to re-seed the generator. For details, see `RandomState`

.

Parameters: **seed** : int or 1-d array_like, optional

So I checked the documentation for `RandomState`

as well and here’s what I found:

*Compatibility Guarantee* A fixed seed and a fixed series of calls to ‘RandomState’ methods using the same parameters will always produce the same results up to roundoff error except when the values were incorrect.

I know it sounds confusing(at least to me) but from what I understand, is that, “a fixed seed” is necessary for `RandomState`

to produce the same results every time. In other words once you execute the code block with `np.random.seed(2)`

, **DON’T** change the seed argument to any other number if you want to reproducibility.

I also found a StackOverflow post - What does `numpy.random.seed(0)`

do? which you can refer to understand the underlying mathematics involved, if you wanted to but I would strongly advice against it since it’s not relevant to the course.

Quoting from that answer, here’s what it had to say:

(pseudo-)random numbers work by starting with a number (the seed), multiplying it by a large number, then taking modulo of that product. The resulting number is then used as the seed to generate the next “random” number. When you set the seed (every time), it does the same thing every time, giving you the same numbers.