How to randomise response screen (textbox)


This is my first time coding and I am having trouble with randomisation with text blocks for my response screen. I haven’t used the coding function yet so I’m unsure how certain parts of the code work with randomisation. As seen from the screenshot I have two boxes “certain” and “probable” i need these to be randomised and swap sides of the screen after stimuli.

As well, I have a practice trial and the rest of the experiment is divided into three blocks so I need to make sure that the coding covers the entire experiment.

Any help would be appreciated. Thank you!


Previously, I’ve achieved this with something similar to this:

#Assuming two textStim components have been initialised earlier called leftText and rightText

import numpy as np

textList = ['PROBABLE', 'CERTAIN']

certSide = np.random.choice(['left', 'right']) #Certain text side

if certSide == 'left':
 leftText.text = textList[1]
 rightText.text = textList[0]
if certSide == 'right':
 leftText.text = textList[0]
 rightText.text = textList[1]

Depending on if you are looking to counterbalance within participants or make it completely random the implementation may differ but the idea is the same. This implementation is quick and dirty but should get the job done.

The way I might go counterbalancing this might be by replacing
certSide = np.random.choice(['left', 'right'])
with a modulo operator to index the list:
certSide = ['left', 'left', 'right', 'right'][int(trialNo) % 4] #This has a predictable pattern so it might need some fine-tuning depending if you wish to counterbalance within or between individuals.

Hopefully, this is helpful! Have fun coding :smile:

1 Like