Pseudorandomization of text

WHAT ARE YOU TRYING TO ACHIEVE?
I want to present 2 types of text stimuli in a pseudorandomized order. The two types are “Visualizar” (presented 60 times) and “Reavaliar” (presented 30 times).

WHAT DID YOU TRY TO MAKE IT WORK?
I created blocks of 10 instructions, in which 6 are gonna be “Visualizar” and 3 are gonna be “Reavaliar”. In order to do so, i created a code component in the routine and had put this in the “Before experiment” tab:

#Create lists of instructions:

useRows_inst =

Visualizar = [‘Visualizar’ * 60]
Reavaliar = [‘Reavaliar’ * 30]

#Pseudorandomize instructions (I created a block of 10 instructions, in which 6 are gonna be “Visualizar” and 3 are gonna be “Reavaliar”):

for blockinst in range(10):
blocklist_inst =
for idxinst in range(6):
blocklist_inst.append(Visualizar.pop())
for idx in range(3):
blocklist_inst.append(Reavaliar.pop())
shuffle(blocklist_inst)
useRows_inst.extend(blocklist_inst)

In the builder, i created a text component, and in the text box i typed “$useRows_inst”.

WHAT SPECIFICALLY WENT WRONG WHEN YOU TRIED THAT?:
When i run the experiment, the text shown is the complete list of instructions, not even randomized.
What i want is that text shows one instruction per time, in the pseudorandomized order i created.

I’m not sure how your code relates to your request, or whether you want blocks of 9 instructions or 10 (since 6+3 = 9). However, is this any help?

blocklist_inst = []
for Idx in range(6)
     blocklist_inst.append('Visualizar')
for Idx in range(3)
     blocklist_inst.append('Reavaliar')
shuffle(blocklist_inst)

To pick one from the list you could pick:

useRows_inst = blocklist_inst.pop()
if len(blocklist_inst) ==0:
     for Idx in range(6)
          blocklist_inst.append('Visualizar')
     for Idx in range(3)
          blocklist_inst.append('Reavaliar')
     shuffle(blocklist_inst)

I tried your solution. Now my hole code is:

Instruction_Code:

#Define lists and shuffle:
blocklist_inst =
for idx in range(6):
blocklist_inst.append(‘Visualizar’)
for idx in range(3):
blocklist_inst.append(‘Reavaliar’)
shuffle(blocklist_inst)

#Pick one from list:
useRows_inst = blocklist_inst.pop()
if len(blocklist_inst) ==0:
for idx in range(6):
blocklist_inst.append(‘Visualizar’)
for idx in range(3):
blocklist_inst.append(‘Reavaliar’)
shuffle(blocklist_inst)

And the text box of the text component is now “$useRows_inst”.

However, now what this code is doing is to pick between “Visualizar” or “Reavaliar” and only shows this one instruction through all the 90 trials.

Which tabs are these code snippets in?

Before experiment tab.

Most of it should be Begin Experiment. Stuff that you want to change each repeat needs to be in Begin Routine.

I moved the second part of the code to the begin routine tab and it worked perfectly!

Thank you!

Just one more question:

How should i save data manually, since the text component is not taking it’s values from a loop?

I know it should be something like this:

thisExp.addData(useRows_inst, name_of_the_text_component)

Is this right?
And should this be at the begin routine tab?

thisExp.addData(‘Instruction’,useRows_inst)
In the begin routine tab

1 Like