# Randomized time interval for fixation cross presentation

**URL:** <https://discourse.psychopy.org/t/randomized-time-interval-for-fixation-cross-presentation/19452>\
**Category:** Builder\
**Created:** [January 7, 2021, 4:30pm UTC](https://discourse.psychopy.org/t/randomized-time-interval-for-fixation-cross-presentation/19452 "2021-01-07T16:30:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kmh](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/kmh/32/15039_2.png) [@kmh](https://discourse.psychopy.org/u/kmh)\
**Post date:** [January 7, 2021, 4:30pm UTC](https://discourse.psychopy.org/t/randomized-time-interval-for-fixation-cross-presentation/19452/1 "2021-01-07T16:30:14Z")

</div>

Hi guys,

I am very new to PsychoPy, do not have any idea about python (yet) and therefore use the builder view completely to build the experiment. I am currently working on a Windows 10, using the PsychoPy version3 (v2020.2.5).

I am currently trying to build a Dichotic Listening Paradigm where an audio stimulus is presented after a randomized period of time. Participants then have to respond using a keyboard press. My current problem is that I am unable to randomize the Inter-Trial-Interval, meaning the time after the response to the previous stimuli and the presentation of the next fixation cross for the next trial. This ITI is supposed to be randomly between 0.5 and 1 seconds. Is there any way to do this using the builder view? If so, where do I need to go and what do I need to add / click? If I have to use the python script to include this information, where would I need to put it?

I hope this is sufficient information and anyone of you will be able to help me with this!

Thank you so much for your help in advance,  
Greetings from Germany

Katrin

---

<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 8, 2021, 11:06am UTC](https://discourse.psychopy.org/t/randomized-time-interval-for-fixation-cross-presentation/19452/2 "2021-01-08T11:06:46Z")

</div>

Hello Katrin,

you need to add a code-element to your iti-routine. Make the code-element the top row of your iti-routine. In the **begin routine tab** add the following code.

This gives you numbers between 0.5 and 1 in steps of 0.1

```auto
iti = randint(5,10)/10

```

If you want to have a finer resolution, you could change the code-element to

```auto
iti = randint(10,20)*0.05

```

That results in steps of 0.05. Use the variable **iti** (or whatever you want to call it) as a duration for your iti-routine.

Best wishes Jens

---

<div class="post-metadata">

**Author:** ![kmh](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/kmh/32/15039_2.png) [@kmh](https://discourse.psychopy.org/u/kmh)\
**Post date:** [January 17, 2021, 7:10pm UTC](https://discourse.psychopy.org/t/randomized-time-interval-for-fixation-cross-presentation/19452/3 "2021-01-17T19:10:49Z")

</div>

Dear Jens,

first of all thank you so much for your quick help and feedback! I have tried to include the code you suggested to my code.

# ------Prepare to start Routine “ITI”-------

iti = random(10,20)\*0.05  
continueRoutine = True

# update component parameters for each repeat

# keep track of which components have finished

ITIComponents = [Fixkreuz]

Is this the correct position?

Unfortunately, I have received the following feedback:

File “…”, line 356, in   
iti = random(10,20)\*0.05  
File “mtrand.pyx”, line 423, in numpy.random.mtrand.RandomState.random  
TypeError: random() takes at most 1 positional argument (2 given)

##### Experiment ended.

I understand this as though I should only write 1 nuber into the function random. However your suggestions says that I should include 2 numbers. Hence, I am a little lost here. Did I not put it at the right position? Is there anything else I need to add? I would be very grateful if you could help me out once more.

Thank you so much,  
Have a great evening  
Best wishes

Katrin

---

<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 18, 2021, 10:20am UTC](https://discourse.psychopy.org/t/randomized-time-interval-for-fixation-cross-presentation/19452/4 "2021-01-18T10:20:10Z")

</div>

Dear Katrin,

sorry, my error. It should read (see attachment)

```auto
iti = randint(10,20)*0.05

```

[iti.psyexp](https://discourse.psychopy.org/uploads/short-url/lTGDdrqC2zKD3uKMpmAC1HIV8nt.psyexp) (6.6 KB) [Stimuli.xlsx](https://discourse.psychopy.org/uploads/short-url/6EwPBdsYzg5990LFCzOfGJSYQ8l.xlsx) (8.4 KB)

Best wishes Jens

---

<div class="post-metadata">

**Author:** ![kmh](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/kmh/32/15039_2.png) [@kmh](https://discourse.psychopy.org/u/kmh)\
**Post date:** [January 28, 2021, 3:43pm UTC](https://discourse.psychopy.org/t/randomized-time-interval-for-fixation-cross-presentation/19452/5 "2021-01-28T15:43:39Z")

</div>

Dear Jens,

thank you so much, it worked!

Best,  
Katrin

---

<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 28, 2021, 7:54pm UTC](https://discourse.psychopy.org/t/randomized-time-interval-for-fixation-cross-presentation/19452/6 "2021-01-28T19:54:34Z")

</div>

Dear Katrin,

Do you mind marking it as solution? Then it is found more easily.

Best wishes Jens
