# Randomizing without repetition

**URL:** <https://discourse.psychopy.org/t/randomizing-without-repetition/19412>\
**Category:** Builder\
**Tags:** randomization\
**Created:** [January 6, 2021, 12:06pm UTC](https://discourse.psychopy.org/t/randomizing-without-repetition/19412 "2021-01-06T12:06:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![omereuveni](https://avatars.discourse-cdn.com/v4/letter/o/90ced4/32.png) [@omereuveni](https://discourse.psychopy.org/u/omereuveni)\
**Post date:** [January 6, 2021, 12:06pm UTC](https://discourse.psychopy.org/t/randomizing-without-repetition/19412/1 "2021-01-06T12:06:48Z")

</div>

**OS** Win10:  
**PsychoPy version** 2020.2.10  
**What are you trying to achieve?:**

Hi all, I’m very ney to PsychoPy and Python so I’m sorry if this is a very basic question. I’ve tried going over answers in the forum and did not quite manage to find a solution.

1. I have a list of 120 stimuli out of which I need to choose 90 for the experiment. Of the 90 I need them to be randomized into three conditions without repetition.
2. I want each condition to appear in a pseudo-random order i.e., not more than twice in a row.

**What did you try to make it work?:**  
1.At the moment I managed to randomize the stimuli but not to withhold repetition.  
2.at the moment the conditions are completely randomized, I didn’t know what to do to control the more than twice in a row issue.

**What specifically went wrong when you tried that?:**  
stimuli are appearing in a random but are repeating more than once

---

<div class="post-metadata">

**Author:** ![Becca](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/becca/32/34260_2.png) [@Becca](https://discourse.psychopy.org/u/Becca)\
**Post date:** [January 6, 2021, 12:26pm UTC](https://discourse.psychopy.org/t/randomizing-without-repetition/19412/2 "2021-01-06T12:26:43Z")

</div>

Hi!

Currently there is no simple ‘out of box’ approach to pseudorandomistion in PsychoPy. For now, we recommend that you make your conditions file in the order that you want and then set your loop type to be ‘sequential’.

If you want a new pseudorandom order for each participant (e.g. 30 participants with their own order) make a unique file for each participant (e.g. ‘conditions1.xlsx’, ‘conditions2.xlsx’ … ‘conditions30.xlsx’)\*. Then in the ‘conditions’ field of your loop use `$'conditions'+expInfo['participant']+'xlsx'` - where` 'expInfo['participant']` will be the number you enter into the participant field of the gui at the start.

Hope this helps,

Becca

\*It will ptobably be most useful long term to make a python script to write your conditions files - and save manual work. Even if you are new to python the skills you learn for this kind of script are a good intro - here is a script that I use for a similar purpose - creating a large number of counterbalanced conditions files [https://gitlab.pavlovia.org/lpxrh6/counterbalance\_conditions](https://gitlab.pavlovia.org/lpxrh6/counterbalance_conditions).

---

<div class="post-metadata">

**Author:** ![omereuveni](https://avatars.discourse-cdn.com/v4/letter/o/90ced4/32.png) [@omereuveni](https://discourse.psychopy.org/u/omereuveni)\
**Post date:** [January 6, 2021, 12:33pm UTC](https://discourse.psychopy.org/t/randomizing-without-repetition/19412/3 "2021-01-06T12:33:54Z")

</div>

Thanks for your quick reply! This answers my second issue perfectly. I still haven’t quite figured out though, how randomly choose stimuli from a list without repetition.

---

<div class="post-metadata">

**Author:** ![JensBoelte](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jensboelte/32/9060_2.png) [@JensBoelte](https://discourse.psychopy.org/u/JensBoelte)\
**Post date:** [January 6, 2021, 2:39pm UTC](https://discourse.psychopy.org/t/randomizing-without-repetition/19412/4 "2021-01-06T14:39:30Z")

</div>

Hello

I am asking simply to understand your experimental intentions better. Why do you use 120 items when you only need 90?

Best wishes Jens

---

<div class="post-metadata">

**Author:** ![Becca](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/becca/32/34260_2.png) [@Becca](https://discourse.psychopy.org/u/Becca)\
**Post date:** [January 6, 2021, 4:18pm UTC](https://discourse.psychopy.org/t/randomizing-without-repetition/19412/5 "2021-01-06T16:18:28Z")

</div>

Hi,

If you have a conditions file that you feed into your loop and set loop type to random, that randomly samples without repetition (repetition is determined by the nReps argument if you do need reps 🙂 )

Thanks,  
Becca

---

<div class="post-metadata">

**Author:** ![omereuveni](https://avatars.discourse-cdn.com/v4/letter/o/90ced4/32.png) [@omereuveni](https://discourse.psychopy.org/u/omereuveni)\
**Post date:** [January 17, 2021, 2:35pm UTC](https://discourse.psychopy.org/t/randomizing-without-repetition/19412/6 "2021-01-17T14:35:22Z")

</div>

Thanks for your reply, the reason for the extra stimuli is that this set of stimuli is being used in two studies one with four conditions (30 stimuli per condition) and the one I consulted about is with only three conditions (30 per condition).

Thanks again,  
Omer
