How to set the same initial seed random numbers in

2019-02-25 17:09发布

I have a matlab code which has a bunch of random numbers such as: unifrnd(0,1), normrnd(mu,sigma), this sort of functions get repeated over and over again.

Is there any way I can fix the random numbers that are generated? Meaning, I run the code once I get some results, on the second run I get different results (as expected). However, I want to make some experiences and it would be really helpful if I could fix the initial seed so that all randomness would be the same on the two runs.

Thanks, V

edit: Would something like this work: rand('seed', 57)

标签: matlab random
1条回答
闹够了就滚
2楼-- · 2019-02-25 17:30

According to the documentation,

rng(seed);

sets the seed of the random number generator.

查看更多
登录 后发表回答