Matlab rand和C ++ rand() [英] Matlab rand and c++ rand()
问题描述
我正在尝试将matlab代码移植到c ++中,并在matlab中找到rand的用法. matlab的rand函数和c ++ rand()函数是否相同? 如果没有,那么在C ++或opencv中是否有用于matlab rand的内置函数?
鉴于C ++标准仅宽松地定义了rand()
,您可以不断言它等同于matlab函数. /p>
幸运的是,C ++ 11现在具有一套生成器,这些生成器在标头<random>
中得到了 的标准化.例如,std::mt19937
是梅森扭曲器生成器,而std::minstd_rand
是线性同余生成器,允许您配置序列系数.
我的猜测是Matlab生成器可以与后者一起复制.有关特定的详细信息,请参考Matlab文档.幸运的是,测试您的代码非常简单.
I am trying to port a matlab code into c++ and found the usage of rand in matlab . Is matlab's rand function and c++ rand() function same? If not, is there any inbuilt function for matlab's rand in C++ or opencv?
Given that the C++ Standard only loosely defines rand()
, you can not assert that it is equivalent to the matlab function.
Fortunately, C++11 now has a suite of generators which are standardised in the standard include header <random>
. For example, std::mt19937
is a Mersenne twister generator and std::minstd_rand
is a linear congruential generator which allows you to configure the sequence coefficients.
My guess is that the Matlab generator can be replicated with this latter one. Refer to the Matlab docs for the specific details. Fortunately, testing your code will be trivial.
这篇关于Matlab rand和C ++ rand()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!