How to set a unified seed for random number genera

2019-05-20 21:53发布

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条回答
Root(大扎)
2楼-- · 2019-05-20 22:16

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.

查看更多
登录 后发表回答