# Randomisation with constraints

**URL:** <https://discourse.psychopy.org/t/randomisation-with-constraints/21885>\
**Category:** Online experiments\
**Tags:** randomization, pavlovia\
**Created:** [March 31, 2021, 7:47am UTC](https://discourse.psychopy.org/t/randomisation-with-constraints/21885 "2021-03-31T07:47:34Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![viviana\_greco](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/viviana_greco/32/5062_2.png) [@viviana\_greco](https://discourse.psychopy.org/u/viviana_greco)\
**Post date:** [March 31, 2021, 1:31pm UTC](https://discourse.psychopy.org/t/randomisation-with-constraints/21885/7 "2021-03-31T13:31:18Z")

</div>

@JensBoelte Sorry for not being clear. Let’s start from the beginning. (unfortunately, I cannot share the exp because of unpleasant stimuli).  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/4/b/4bd1bed77dc82709bcf51e025b55b3af39c50d6b.png)

LEARN 1: participants learn associations between sounds (24) and shapes (48).  
Each sound is paired with 2 different shapes. (e.g. Trial1: sound A – shape 1 / Trial2: sound A – shape 2 …… Trial47: sound 24 – shape 47 / Trial48: sound 24 – shape 48).  
MULTIPLEC\_1: participants are tested on the learnt associations. I have 48 trials in which participants will hear a sound and have to choose the correct shape previously paired with it between 4 different shapes.

![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/5/9/591a899af4968b10da8bc09f2ededea615f12bf1.png)

My excel file in the “MC1 loop” looks like that:

![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/8/0/80c99d7c2b7954cf198d32acc09eaf3d4c40b024.png)

In each row I have one sound, 4 shapes and the correct answer.  
the “MC1” loop is set to be random.  
However, I want to avoid that participants will hear the same sound consecutively. Therefore, I would like something like that:

![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/0/c/0cc85e17b89ea44c7f9d58b12ca3fe3f5e313729.png)

Trial 1: Green row  
Trial 2 : yellow row  
Trial 3 : blue row  
Trial 4 : red row… etc

The experiment is perfectly working online with JS code, I would only like to make sure that when participants are tested on the learnt associations, the same sound will not be presented consecutively.

---

_[View the full topic](https://discourse.psychopy.org/t/randomisation-with-constraints/21885)._
