# Random allocation of stimuli on screen

**URL:** https://discourse.psychopy.org/t/random-allocation-of-stimuli-on-screen/6172
**Category:** Coding
**Created:** [December 28, 2018, 6:32pm UTC](https://discourse.psychopy.org/t/random-allocation-of-stimuli-on-screen/6172 "2018-12-28T18:32:24Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![cat500](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/cat500/32/7508_2.png) [@cat500](https://discourse.psychopy.org/u/cat500)
#### Post date: [December 28, 2018, 6:32pm UTC](https://discourse.psychopy.org/t/random-allocation-of-stimuli-on-screen/6172/1 "2018-12-28T18:32:24Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Michael](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/michael/32/16_2.png) [@Michael](https://discourse.psychopy.org/u/Michael)
#### Post date: [December 29, 2018, 12:16am UTC](https://discourse.psychopy.org/t/random-allocation-of-stimuli-on-screen/6172/2 "2018-12-29T00:16:42Z")

</div>

```auto
# 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]`
