Skip to content

Commit 52212fe

Browse files
committed
add coverage for the most modern to very old matlab version
1 parent 243c377 commit 52212fe

File tree

1 file changed

+37
-7
lines changed

1 file changed

+37
-7
lines changed

src/utils/setUpRand.m

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
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);
@@ -13,8 +19,32 @@
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

0 commit comments

Comments
 (0)