How to set custom seed for pseudo-random number generator

后端 未结 4 1903
后悔当初
后悔当初 2020-11-30 09:38

I need to perform few tests where I use randn pseudo random number generator. How can I set the seed on my own, so every time I run this test I will get the sam

4条回答
  •  心在旅途
    2020-11-30 10:37

    When you just want to reset the RNG to some known state, just use:

     seed = 0;
     randn('state', seed);
     rand ('state', seed);
     A = round(10*(rand(1,5))); // always will be [10 2 6 5 9]
    

提交回复
热议问题