Random Without Replacement (over multiple blocks)

Figured out a much more elegant solution, so thought I’d update in case anyone had the same problem. (got it from this discourse: Exit a loop on pavlovia - #30 by Kath_K)

There are two different conditions files for the wnw and PM routines. It samples 5 trials from the WNW trial, breaks out, and samples once from the PM trial, then loops back to the beginning (code2). This repeats 8 times. It samples randomly and without replacement.

################################################
Code1 JS - Begin Experiment:
// Make array for PM cues
// There are 8 stories in each file
pmArr = […Array(8).keys()];
util.shuffle(pmArr)

// make array for stimLoop
// There are 40 stimuli
stimArray = […Array(40).keys()];
util.shuffle(stimArray)

Code1 JS - Begin Routine:
// Get the next PM cue
pmRow = ;
if (blockType == 1) {
val = pmArr.pop()
}

pmRow.push(val);
pmRow.push(val);

Code2 JS - Begin Routine:
// Get 5 stim
currentArray =
for (let i=0; i<5; i++) {
if (blockType == 1) {
currentArray.push(stimArray.pop())
}
}
################################################

1 Like