std::mt19937 gen(2007)
我在 C++ 和RandStream.create('mt19937ar','seed',2007)
Matlab 中尝试过。我也尝试过不同的结构,但我找不到特定的种子结构来在 Matlab 和 c++ 之间找到相同的随机数。我该如何处理?
2 回答
1
The difference (most likely) stems from the use of uniformly-distributed pseudo-random numbers in C++, while MATLAB code uses normally-distributed pseudo-random numbers. Try rand
/randi
instead randn
in the MATLAB code (i.e. unformly-distributed integers instead of normally distributed doubles).
More on MATLAB side of the story: http://www.mathworks.com/help/matlab/random-number-generation.html
于 2014-07-23T11:36:08.060 回答