Creating two random conditions

Hi, I’m trying to have my experiment have 2 different conditions given at random. As of right now, I have the participants view 80 images in one condition, and then in sequence have them view 80 images in another condition. I am trying to have it so they only experience only one of them, chosen at random. If anyone could help that would be greatly appreciated

what I have
Intro → experiment 1 → experiment 2 → over

What I’m trying to make
Intro → just experiment 1 or 2 → over

Create a code component in your intro. When your experiment starts, choose a random int between 0 and 1:

#Begin Experiment:
import random
chooseExperiment = random.randint(0, 1)

Now, create a code component both in experiment 1 and experiment 2. The code will test the value of the chooseExperiment variable.
One experiment will check if the int is 0, and one will check if it’s 1:

# Begin Routine
if chooseExperiment:
    continueRoutine = False
# Begin Routine
if not chooseExperiment:
    continueRoutine = False

Because the numbers 0 and 1 can be seen as booleans, we don’t have to specify a condition such as if chooseExperiment == 0:.

Experiment Example:
1cond.psyexp (22.8 KB)



import random

will cause problems in case you plan to run the experiment online.

You might rather use

chooseExperiment = randint(0,2)

I am not quite sure if randint auto-translates correctly to JS. So you might to add the following function to a JS-only code-component

randint = function(min, maxplusone) {
  return Math.floor(Math.random() * (maxplusone - min) ) + min;

see also here

Best wishes Jens

chen u are amazing, tysm

1 Like

You are also amazing jens, ty as well

One last question: this is the same study you assissted me with last week with the random image locations. With data collection in the excel sheet, would you happen to know how to store what side of the screen the image appeared on with the stored key input that they gave? As of right now, the excel sheet made by the experiment only attaches the inputs they gave, but it doesnt say if they were correct/the image location for me to determine if they were correct. Thanks

Yes, actually, @wakecarter mentioned exactly this in your last post: see here.
Did you try it?

1 Like