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.