How to set the same initial seed random numbers in

2019-02-25 17:03发布

问题:

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)

回答1:

According to the documentation,

rng(seed);

sets the seed of the random number generator.



标签: matlab random