File tree Expand file tree Collapse file tree 1 file changed +37
-7
lines changed
Expand file tree Collapse file tree 1 file changed +37
-7
lines changed Original file line number Diff line number Diff line change 1- function [] = setUpRand()
2- % Set up the randomizers for uniform and normal distributions.
1+ % (C) Copyright 2010-2020 Sam Schwarzkopf
2+ % (C) Copyright 2020 CPP_PTB developers
3+
4+ function setUpRand()
5+ % setUpRand()
6+ %
7+ % Resets the seed of the random number generator. Will "adapt" depending on the matlab/octave
8+ % version.
39 % It is of great importance to do this before anything else!
4-
10+ %
511 % For an alternative from PTB see `ClockRandSeed`
612
713 seed = sum(100 * clock );
1319
1420 else
1521
16- RandStream .setGlobalStream(RandStream(' mt19937ar' , ' seed' , seed ));
17-
22+ try
23+ % Use the reccomended method in modern Matlab
24+ RandStream .setGlobalStream(RandStream(' mt19937ar' , ' seed' , seed ));
25+ disp(' Using modern randomizer...' );
26+ catch
27+
28+ try
29+ % Use the recommended method in Matlab R2012a.
30+ rng(' shuffle' );
31+ disp(' Using less modern randomizer...' );
32+ 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
47+ end
48+ end
49+
1850 end
19-
20- end
You can’t perform that action at this time.
0 commit comments