How to set a unified seed for random number generators in MATLAB?

会有一股神秘感。 提交于 2019-12-22 11:26:31

问题


I'm writing code and using existing functions from MATLAB. What if these functions use random number generators. Is there a way I can fix the seed of these functions without having to change their code ? Is there a command in MATLAB that does this ?


回答1:


Normally code would use Matlab's built-in random number generator. You can seed it with the following:

rng         = RandStream.getDefaultStream;
rng.reset(your_seed_value_here);

One could also create RandStream objects and use them (thereby avoiding the default stream), but this should work most of the time.



来源:https://stackoverflow.com/questions/5891443/how-to-set-a-unified-seed-for-random-number-generators-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!