Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cross platform numpy.random.seed()

The docs say:

Compatibility Guarantee 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 except when the values were incorrect. Incorrect values will be fixed and the NumPy version in which the fix was made will be noted in the relevant docstring. Extension of existing parameter ranges and the addition of new parameters is allowed as long the previous behavior remains unchanged.

There is no mention of operating systems.

If I call np.random.seed(42) on windows and linux, will the random numbers generated afterwards be the same ? Will it be the same across different versions of 64bit Ubuntu ?

I assume that the rng uses system libraries, so the code is probably not portable. If that's true, is there a fix ? I know that this would probably be ugly, like changing the linux rng system for something that emulates windows. But I'm ready for creative solutions.

like image 651
lhk Avatar asked Nov 18 '16 11:11

lhk


People also ask

Does random seed work for Numpy?

The numpy random seed is a numerical value that generates a new set or repeats pseudo-random numbers. The value in the numpy random seed saves the state of randomness. If we call the seed function using value 1 multiple times, the computer displays the same random numbers.

Is Numpy random seed Global?

It uses global state, which means results will change as the code changes. It uses a RandomState rather than the more modern Generator .

What does seed () function do?

The seed() method is used to initialize the random number generator. The random number generator needs a number to start with (a seed value), to be able to generate a random number. By default the random number generator uses the current system time.

What seed does Python random use?

In the Python random module, the . seed() method is used to create a pseudo-random number generator. Pseudo-random number generators appear to produce random numbers by performing some operation on a value. This value is the seed and it sets the first “random” value of the number sequence.


1 Answers

As per sascha’s comment, random numbers are platform independent.

like image 189
lhk Avatar answered Sep 19 '22 15:09

lhk