Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/00_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ let PTB find and use the default device.
## 3. <a name='functionsdescriptions'></a>functions descriptions

The main functions of the toolbox are described
[here](./10_functions_descriptions.md).
[here](./10_functions_description.md).

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

Expand Down
6 changes: 6 additions & 0 deletions docs/10_functions_description.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
- 6.1. [shuffle](#shuffle)
- 6.2. [setTargetPositionInSequence](#setTargetPositionInSequence)
- 6.3. [repeatShuffleConditions](#repeatShuffleConditions)
- 6.4. [setUpRand](#setUprand)

<!-- vscode-markdown-toc-config
numbering=true
Expand Down Expand Up @@ -214,3 +215,8 @@ they are not in consecutive positions.
Given `baseConditionVector`, a vector of conditions (coded as numbers), this
will create a longer vector made of `nbRepeats` of this base vector and make
sure that a given condition is not repeated one after the other.

### 6.4. <a name='setUpRand'></a>setUpRand

Resets the seed of the random number generator. Will "adapt" depending on the matlab/octave version.
It is of great importance to do this before anything else!
42 changes: 42 additions & 0 deletions src/utils/setUpRand.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
% (C) Copyright 2010-2020 Sam Schwarzkopf
% (C) Copyright 2020 CPP_PTB developers

function setUpRand()
% setUpRand()
%
% Resets the seed of the random number generator. Will "adapt" depending on the matlab/octave
% version.
% It is of great importance to do this before anything else!
%
% For an alternative from PTB see `ClockRandSeed`

seed = sum(100 * clock);

try
% Use the reccomended method in modern Matlab
RandStream.setGlobalStream(RandStream('mt19937ar', 'seed', seed));
disp('Using modern randomizer...');
catch

try
% Use the recommended method in Matlab R2012a.
rng('shuffle');
disp('Using less modern randomizer...');
catch

try
% Use worse methods for Octave or old versions of Matlab (e.g. 7.1.0.246 (R14) SP3).
rand('twister', seed);
randn('twister', seed);
disp('Using Octave or outdated randomizer...');
catch
% For very old Matlab versions these are the only methods you can use.
% These are supposed to be flawed although you will probably not
% notice any effect of this for most situations.
rand('state', seed);
randn('state', seed);
disp('Using "flawed" randomizer...');
end
end

end