# Random allocation of stimuli on screen

Hello,

I am coding a Serial Reaction Time on Psychopy and I have been looking for a way to randomly present the stimuli on screen. For those who are not familiar with this task, my version basically follows a sequence of positions that I defined (labelled 1 to 4), however I do not want 1 to always correspond to the same position on screen, I want it to be selected at random. Let’s pretend there are four rectangles on screen and they are labelled from A to D, I want to code it so that 1 can correspond to A, B, D or D depending on the participant.

For the first participant: 1 could correspond to A, 2 to C, 3 to D and 4 to B
for the second participant: 1 could correspond to position D, 2 to A, 3 to B and 4 to C, and so on.

Is that a simpler way than creating a spreadsheet with all the possibilities?

Thank you,

Cat

``````# list the names of your existing rectangle stimuli:
rectangles =  [A, B, C, D]

# and whatever the positions are (i.e. these could each be [x, y]
# lists  or tuples rather than just single values):
positions = [1, 2, 3, 4]

# randomise the assignment:
numpy.random.shuffle(rectangles)

# zip the lists together and make a dictionary to link their entries:
correspondences = dict(zip(positions, rectangles))
``````

To get the stimulus corresponding to a given position, something like: `correspondences[1]`

1 Like