Skip to content

Commit 199069e

Browse files
authored
Merge pull request #113 from marcobarilari/marco_setUpRand
setUpRandom
2 parents 6172baf + 323259e commit 199069e

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

docs/00_index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ let PTB find and use the default device.
193193
## 3. <a name='functionsdescriptions'></a>functions descriptions
194194

195195
The main functions of the toolbox are described
196-
[here](./10_functions_descriptions.md).
196+
[here](./10_functions_description.md).
197197

198198
## 4. <a name='Annexes'></a>Annexes
199199

docs/10_functions_description.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
- 6.1. [shuffle](#shuffle)
2727
- 6.2. [setTargetPositionInSequence](#setTargetPositionInSequence)
2828
- 6.3. [repeatShuffleConditions](#repeatShuffleConditions)
29+
- 6.4. [setUpRand](#setUprand)
2930

3031
<!-- vscode-markdown-toc-config
3132
numbering=true
@@ -214,3 +215,8 @@ they are not in consecutive positions.
214215
Given `baseConditionVector`, a vector of conditions (coded as numbers), this
215216
will create a longer vector made of `nbRepeats` of this base vector and make
216217
sure that a given condition is not repeated one after the other.
218+
219+
### 6.4. <a name='setUpRand'></a>setUpRand
220+
221+
Resets the seed of the random number generator. Will "adapt" depending on the matlab/octave version.
222+
It is of great importance to do this before anything else!

src/utils/setUpRand.m

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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.
9+
% It is of great importance to do this before anything else!
10+
%
11+
% For an alternative from PTB see `ClockRandSeed`
12+
13+
seed = sum(100 * clock);
14+
15+
try
16+
% Use the reccomended method in modern Matlab
17+
RandStream.setGlobalStream(RandStream('mt19937ar', 'seed', seed));
18+
disp('Using modern randomizer...');
19+
catch
20+
21+
try
22+
% Use the recommended method in Matlab R2012a.
23+
rng('shuffle');
24+
disp('Using less modern randomizer...');
25+
catch
26+
27+
try
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...');
32+
catch
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...');
39+
end
40+
end
41+
42+
end

0 commit comments

Comments
 (0)