| Reference | Downloads | Github

Create random Inter-trial-interval duration

Hi everyone,

Description of the problem: For my first experiment (programmed in builder, version 2021.1.4; needs to run online) I need an inter-trial-interval that varies between 3 and 5 seconds per trial in one routine (see picture below).

What I tried so far:

  1. I added a code component (Begin Routine tab): Math.random(3,5.1)
  2. As I want a black background for the time of the ITI, I added a image component (just a black page) and put “ITI” into the duration tab


Code component:

ITI as duration for the Black Background.

When I run it offline, I always add import random to the begin experiment tab and use random.uniform(3,5.1) for the begin routine tab. However this doesn’t work online (stuck at initialising experiment).
The Math.random function actually worked till today, so I really don’t know what happened…

Thank’s in advance for your help!

Hello Elani,

delete the import random. This results in an error when running the experiment on-line as you noticed. Add a code_JS only component in a Begin Experiment tab including the following line: random = Math.random;

Shouldn’t the ITI in the Stop parameter be preceded by a $? So $ITI instead of ITI.

Worked for me.

Best wishes Jens

Hi Jens,

thank you for your reply.
I tried what you suggested but unfortunately it is not working…
When I add random = Math.random; in the Begin Experiement tab and leave the Stop parameter to ITI (no dollar sign) it just ignores the ITI at all (starts with a Fixation cross that should begin after a black screen).
I then tried it again with a dollar sign but then I just get the error following error: ReferenceError: $ITI is not defined

For the stop parameter I tried duration as well as condition but with both I get the error…
Best regards

Hello Elani,

did you initialize ITI at the Begin of the experiment? ITI = 0

Best wishes Jens

Hi Jens,

thanks for your reply. I did not initialize ITI at the Begin of the experiement but I tried it right away!
However, when I try to run it online it still ignores the time of ITI and goes right to the fixation cross.

Here is what my code looks like, maybe I still get something wrong (I also tried it with $ITI again, but then I get the error that $ITI is not defined):

Thank you so much for your help!

Hello Elani,

here an example of a variable iti that sets both, the duration and the onset.

iti.psyexp (8.4 KB)
Stimuli.xlsx (8.4 KB)

Best wishes Jens


this really works, thank you so much! I still have to do it without the $ sign before the ITI, but then it looks like it works just fine :slight_smile:

The example was really helpful! However, do you mind to explain to me why the ITI variable needs to be both Start and Duration? I mean, I actually define the ITI to present the black image for the specified duration so why do I also add the ITI in the Start field?
Maybe it will help me the next time if I get that :slight_smile:

Thanks again for everything! :slight_smile:
Best wishes

Hello Elani,

I inserted the ITI in both fields to show that you can use variables in the Start and the Duration field.

Best wishes Jens