Skip to content

Commit

Permalink
Added code for making sequences
Browse files Browse the repository at this point in the history
  • Loading branch information
jpeelle committed Mar 10, 2020
1 parent 9a20ec7 commit babb1c8
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
70 changes: 70 additions & 0 deletions jp_makesequences.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
function seq = jp_makesequences(digitList, numSequences, sequenceLength, repeatProbability)
%JP_MAKESEQUENCES Make non-repeating numeric sequences, 1 per row.
%
% NB: Setting repeatProbability to 0 does not mean there is a 0% chance of
% a repeat; it simply turns off the function. I.e., if repeatProbability is
% set to 0, each digit is chosen at random from digitList.

if nargin < 1 || isempty(digitList)
error('Must specify list of digits (e.g., [2 3 4 5].');
end

if nargin < 2 || isempty(numSequences)
numSequences = 5;
end

if nargin < 3 || isempty(sequenceLength)
sequenceLength = 9;
end

if nargin < 4 || isempty(repeatProbability)
repeatProbability = 0;
end


verbose = 1;

seq = zeros(numSequences, sequenceLength);

if verbose > 0
fprintf('\nGenerating sequences\n\n');
end

for seqCounter = 1:numSequences

if verbose > 0; fprintf('Sequence %04i/%04i...', seqCounter, numSequences); end

alreadyExists = 1;

while alreadyExists==1

thisSeq = zeros(1, sequenceLength);

% start with a random digit
thisSeq(1) = digitList(round((rand * (length(digitList)-1))) + 1);

for digitCounter = 2:sequenceLength
if repeatProbability > 0
if rand < repeatProbability
thisSeq(digitCounter) = thisSeq(digitCounter-1);
else
thisSeq(digitCounter) = digitList(round((rand * (length(digitList)-1))) + 1);
end
else
thisSeq(digitCounter) = digitList(round((rand * (length(digitList)-1))) + 1);
end
end % going through digits in this sequence



if ~ismember(thisSeq, seq, 'rows')
alreadyExists = 0;
end

end % checking alreadyExists in while loop

seq(seqCounter,:) = thisSeq;

if verbose > 0; fprintf('done.\n'); end

end % going through numSequences
22 changes: 22 additions & 0 deletions jp_makesequences_wrapper.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
% Relies on jp_makesequences from http://github.com/jpeelle/jp_matlab


% Make two sets of patterns, "easy" (higher likelihood of repeating numbers)
% and "hard" (each number in the sequence chosen at random.


digitList = [2:5];
numSequences = 500;
sequenceLength = 9;
repeatProbability = .3;


easySequences = jp_makesequences(digitList, numSequences, sequenceLength, repeatProbability);
dlmwrite('~/easySequences.tsv', easySequences, '\t');


repeatProbability = [];

hardSequences = jp_makesequences(digitList, numSequences, sequenceLength, repeatProbability);
dlmwrite('~/hardSequences.tsv', easySequences, '\t');

0 comments on commit babb1c8

Please sign in to comment.