I have 3 types of stimuli (4 shapes, 8 letters, 8 numbers) and 128 trials and I want to ensure no exact stimulus repeats. We first attempted to generate the entire list of 128 stimuli and force randomization of the list until there were no repeats, but this seemed to run indefinitely. I then changed to a random without replacement strategy, where each stimulus list is shuffled and then an item is selected with pop and the list is replenished once all items have been selected. This worked pretty well, but still needs to check for repeats. I have the code snippet for one list below. I keep getting repeats in the list despite the while loop check. Is there an error in the code? Thanks!
import numpy as np
stimCounts=128;
shapeStims=[]
prevShape=-1
for trials in range(0, stimCounts):
if trials in range(0,stimCounts,4):
shapelist = ['square','diamond','hexagon','star']
np.random.shuffle(shapelist)
checkforreps = True
while checkforreps:
currshape=shapelist[-1]
if currshape == prevshape:
np.random.shuffle(shapelist)
break
else:
checkforreps = False
currshape=shapelist.pop(-1)
prevshape=currshape
shapeStims.append(currshape)