-2

I would like, in python, to permutate the lines of various 2x2 numpy.array() at any time. Can I rely on seed in order to make sure that the permutation will be always the same if a fix the random.seed() to some integer before every permutation? Can I find some explanation that can convince me that this method is reliable?

Waliston
  • 17
  • 1
  • 3

1 Answers1

1

The very purpose of fixing the seed with random.seed is to be able to consistently produce the same pseudo-random numbers after resetting the seed to a known value. So yeah, if your permutations rely on (pseudo-)random state, then setting the seed to a known constant will prime the algorithm to generate the same sequence of permutations every time.

From the docs (which is about as convincing as it gets):

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...

>>> import numpy as np
>>> np.random.seed(5)
>>> np.random.rand()
0.22199317108973948 # (1)
>>> np.random.rand()
0.8707323061773764 # (2)
>>> np.random.seed(5)  # re-seed
>>> np.random.rand()
0.22199317108973948 # same as (1)
>>> np.random.seed(5)
>>> np.random.rand()
0.22199317108973948 # same as (1) again
>>> np.random.rand()
0.8707323061773764 # same as (2)
ForceBru
  • 43,482
  • 10
  • 63
  • 98