@@ -12,38 +12,30 @@ function setUpRand()
1212
1313 seed = sum(100 * clock );
1414
15- if isOctave
16-
17- rand(' twister' , seed );
18- randn(' twister' , seed );
19-
20- else
15+ try
16+ % Use the reccomended method in modern Matlab
17+ RandStream .setGlobalStream(RandStream(' mt19937ar' , ' seed' , seed ));
18+ disp(' Using modern randomizer...' );
19+ catch
2120
2221 try
23- % Use the reccomended method in modern Matlab
24- RandStream .setGlobalStream(RandStream( ' mt19937ar ' , ' seed ' , seed ) );
25- disp(' Using modern randomizer...' );
22+ % Use the recommended method in Matlab R2012a.
23+ rng( ' shuffle ' );
24+ disp(' Using less modern randomizer...' );
2625 catch
2726
2827 try
29- % Use the recommended method in Matlab R2012a.
30- rng(' shuffle' );
31- disp(' Using less modern randomizer...' );
28+ % Use worse methods for Octave or old versions of Matlab (e.g. 7.1.0.246 (R14) SP3).
29+ rand(' twister' , seed );
30+ randn(' twister' , seed );
31+ disp(' Using Octave or outdated randomizer...' );
3232 catch
33-
34- try
35- % Use worse methods for old versions of Matlab (e.g. 7.1.0.246 (R14) SP3).
36- rand(' twister' , seed );
37- randn(' twister' , seed );
38- disp(' Using outdated randomizer...' );
39- catch
40- % For very old Matlab versions these are the only methods you can use.
41- % These are supposed to be flawed although you will probably not
42- % notice any effect of this for most situations.
43- rand(' state' , seed );
44- randn(' state' , seed );
45- disp(' Using "flawed" randomizer...' );
46- end
33+ % For very old Matlab versions these are the only methods you can use.
34+ % These are supposed to be flawed although you will probably not
35+ % notice any effect of this for most situations.
36+ rand(' state' , seed );
37+ randn(' state' , seed );
38+ disp(' Using "flawed" randomizer...' );
4739 end
4840 end
4941
0 commit comments