在Matlab解决种子R2011b | RandStream失败的原因吗?
7视图(30天)
显示旧的评论
我使用下面的代码来解决在Matlab R2011b种子
s = RandStream (“mt19937ar”、“种子”,0);
RandStream.setGlobalStream(年代);
然后我试着画一些制服/普通/ wishart随机数在成千上万的迭代,但随机数是一样的只是第一次迭代当我重启Matlab。迭代:
i = 1: n
一个=兰德(1,1);
b = randn (3,1);
c = wishrnd(ωt);
结束
虽然它不工作我真正感兴趣的复杂的代码,我尝试了一个更简单的版本上面,每当我重启Matlab工作。
我真的困惑什么是失败的根源。任何见解都欣赏。多谢。
艾伦
0评论
答案(4)
彼得·珀金斯
2012年8月1日
艾伦,我不能告诉你是什么意思,“随机数是一样的只是第一次迭代,当我重启Matlab。”You may mean that you expect to be able to restart MATLAB, run the same code, and see exactly the same numbers in all iterations of the loop, and what you actually see is that they are the same only for the first iteration. If you are really executing those first two lines that set the global random number stream, then you should get repeatable results. In fact, since those two lines do exactly what MATLAB already does at startup, you should see repeatable results even if you don't execute them.
这将是好如果你能提供更具体的信息。
如果以上你是什么意思,那么一定是在你的代码,你没有提到。特别是因为你不能复制prblem在一个简单的例子。我的建议是在代码中设置断点的时候,你认为事情已经错了。当执行停止断点,检查,看看全球流,因为它是可能的,你打电话是改变它的代码。
除此之外,你必须更具体。希望这个有帮助。