8

In Python's numpy library, the np.random.seed method can accept two different types of parameter: int and array_like[int].

What's the difference between them? Such as: np.random.seed(2) and np.random.seed([2013, 1, 4]).

1 Answer 1

8

The state of the underlying Mersenne Twister PRNG is very large, 624 32-bit integers, to be exact. If given an integer seed, the initialization routine will run a smaller PRNG to expand that single 32-bit integer out to the full 624-element state. This does mean that you can't access the vast majority of the possible states.

Similarly, if given a sequence of integers as the seed, then a different smaller PRNG will use that to expand out to 624 elements, but one that can use the whole array that you pass it. This lets you access the whole space of initial states, if such a thing matters to you. This algorithm is shared between the standard library's random module and numpy.random.

Sign up to request clarification or add additional context in comments.

2 Comments

So the only difference between single integer and array_like parameter is that the size of space of initial state? It makes no difference to the generation of random number?
That's right. The algorithm after initialization is precisely the same.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.