0
votes

What is algorithm that Python Numpy uses to generate random numbers? More specifically, what is the algorithm that is used when we invoke

np.random.uniform() 

Is Linear congruential generator random generation technique being used? What happens when we type

np.random.seed(42)

and why are some numbers like 42 are more popular with np.random.seed?

1
1) Mersenne Twister 2) Seeding is PRNG-dependent and for MT there are scientific-papers available by the original authors on how to seed properly. 3) Because of A common book - sascha

1 Answers

2
votes
  1. Numpy uses the Mersenne Twister (as does the cpython random module).
  2. When you seed the random number generator you're choosing its current state (a PRNG chooses its next state based on its current state and chooses its current value as a function of its current state. Some other PRNG's simply use the identity function to generate a value from a state).
  3. The choice of seed doesn't matter much except that it be the same across multiple runs to ensure reproducibility. The number 42 is commonly chosen any time an arbitrary number needs to be picked, especially in nerdier social circles, because of its position as "the answer to life, the universe, and everything" according to a popular book. Other small, memorable numbers are often chosen for seeds as well.