In Python's program, the following pseudo-random number generation code was found
RNG = Numpy.random.RandomState (23355) Arraya = Rng.uniform (0,1, (2,3))
The purpose of this code is to produce a assarray of 2 rows and 3 columns, where each element is a uniformly distributed random number of [0,1] intervals.
Here to see, there is a 23355 this number, in fact, it is the seed of the pseudo-random number generator, that is, "the starting point for a sequence of pseudorandom"
For a pseudo-random number generator, as long as the seed (seed) is the same, the resulting sequence of random numbers is the same
Here are a few small examples
1 # still takes the seed above as an example, but executes multiple times 2 # use loops to perform 4 times 3 Import NumPy 4 for inch [1,2,3,4]: 5 RNG = Numpy.random.RandomState (23455)6 Arraya = Rng.uniform (0,1, (2,3))7 Print Arraya
The result of changing the code snippet is as follows:
As you can see, the pseudo-random numbers produced by each loop are the same, because each pseudo-random number generator has the same seed.
Now, let's look at another example.
1 import NumPy 2 for i [1,2,3,4 3 rng = Numpy.random.RandomState (23455+i) 4 Arraya = Rng.uniform (0,1, (2,3)) 5 print ( i =%s ' %
Here, we made a small change, each time the seed of the cycle is added I, because each cycle I value different, resulting in each cycle of the seed is also different, the following is the result of changing the program section
It can be seen that the random asarray of the 2*3 produced by each cycle are different.
Seed in Nump for the random number generator