Is there the same seed for Matlab Random and C ++ Random?

I tried std::mt19937 gen(2007) in C ++ and RandStream.create('mt19937ar','seed',2007) in Matlab. I also tried different structures, but I could not find a specific seed structure to search for the same random numbers between Matlab and C ++. How can I handle this?

+6
source share
2 answers

You want the random generator to be deterministic and work the same in two different implementations.

There is no guarantee that implementations of Matlab and C ++ :: std will generate the same results. Although it would be wise to think that they should - this is the same algorithm. According to Wikipedia , there are options for implementations. The most remarkable difference between the 32 and 64-bit implementation, which gives different results.

To overcome this obstacle, generate numbers in one tool, and then use the same sequence in another. Or use your own algorithm - some ideas here .

+3
source

The difference (most likely) is related to the use of uniformly distributed pseudo-random numbers in C ++, while the MATLAB code uses normally distributed pseudo-random numbers. Try rand / randi instead of randn in MATLAB code (i.e. Informally distributed integers instead of normally distributed doubles).

More on MATLAB side: http://www.mathworks.com/help/matlab/random-number-generation.html

+1
source

Source: https://habr.com/ru/post/972690/


All Articles