2
votes

I'm having problems to compare the output of two code because of random number state.

I'm comparing the MATLAB randperm function with the output of the equivalent numpy.random.permutation function but, even if I've set the seed to the same value with a MATLAB rand('twister',0) and a python numpy.random.seed(0) I'm obtaining different permutations.

I've to say that the result of MATLAB's rand and numpy numpy.random.rand are the same if the seed are set like above.

1
They may be using different random number generation algorithms. In that case, even if the seed is the same, the output will be different. - Ffisegydd
If you just need to compare to codes, you can output a sufficient number of your random permutations using either Matlab or Python and save them to a file. Then the other version can just read in the values from file. This may be the simplest workaround. - horchler

1 Answers

1
votes

This is a common issue. While the random number generator is identical, the function which converts your random number stream into a random permutation is different. There is no specified standard algorithm which describes the expected result.

To solve this issue, you have to use the same library in both tools.