2012年1月7日 星期六

Unique rand in MATLAB

The rand function in MATLAB is generated by a long vector containing "random" numbers. The sequence is therefore important. Without setting the sequence, the random numbers always appear in series like

0.8147    0.9058    0.1270    0.9134    0.6324 ...,

whenever MATLAB is restarted. To make sure the random numbers do not appear in the same sequence, one can first

s = RandStream('mt19937ar','seed',sum(100*clock));

and then execute rand(s,n,m). This makes sure that the sequence would hardly repeat when starting MATLAB at different time.

沒有留言:

張貼留言