np.random.seed(0) makes unpredictable random numbers
>>> numpy.random.seed(0) ; numpy.random.rand(4) array([ 0.55, 0.72, 0.6 , 0.54]) >>> numpy.random.seed(0) ; numpy.random.rand(4) array([ 0.55, 0.72, 0.6 , 0.54])
When sowing reset (each time), the same set of numbers will be displayed each time.
If the random seed is not reset, different numbers appear with each call:
>>> numpy.random.rand(4) array([ 0.42, 0.65, 0.44, 0.89]) >>> numpy.random.rand(4) array([ 0.96, 0.38, 0.79, 0.53])
(pseudo) random numbers work, starting with a number (seed), multiplying it by a large number, then taking modulo this product. The resulting number is then used as a seed to generate the next "random" number. When you plant a seed (each time), it does the same every time, giving you the same numbers.
If you want seemingly random numbers, do not set the seed. However, if you have code that uses random numbers that you want to debug, it can be very useful to set the seed before each run so that the code does the same every time it runs.
To get the most random numbers for each run, call numpy.random.seed() . This will cause numpy to set the seed to a random number obtained from /dev/urandom or its Windows counterpart, or, if none of them are available, will use the clock.
John1024 Feb 01 '14 at 5:48 2014-02-01 05:48
source share