Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Experiment crashes due to long random list generation

Hey everyone!

After a couple of weeks of trial and error, I finally managed to implement an experiment with a couple tricky constraints. The idea is, that every trial, either a number or a letter is shown. There's a 75:25 chance that after each trial, there's a switch (letter-number) or a repetition (letter-letter) of the stimulus type. The constraint here is, that the rare 25%-of-the-times trial transition (switch or repetition) doesn't occur twice in a row. To achieve this, I have opensesame generate a list containing "switch" or "repetition", as many times as there are trials. When I only did this for 32 trials for testing purposes, everything was fine. But when I set that up to the 384 trials that I need for my actual experiment, it won't start, I think the reshuffling until my constraints are met is causing the crash. What can I do?

Here's my code, pieced together from various forum posts

#setting up the list of task switches / repeats in the 75:25 ratio, while ensuring that the rare condition isn't repeated in two consecutive trials
from random import shuffle


global switch_list # Make switch_list global so we can use it later
switch_list = ["repeat", "repeat", "repeat", "switch"] # Create a list of 75:25 ratio of switch / repeat
switch_list *= 96 # multiply list to get needed amount of trials
shuffle(switch_list) # Randomize the list


# Now check if the rare condition is repeated immediately (e.g, switch, repeat, repeat, switch)
# and randomize until this is not the case
while True:
	reshuffle = False #determine if we have to reshuffle
	for i in range(len(switch_list)-1): #set i to the penultimate element of the list 
		if switch_list[i] == switch_list[i+1] == "switch": #check if both i and i+1 have the same value of the rare condition
			reshuffle = True #if yes, we need to reshuffle
			break
	if not reshuffle: #if not, we can break the while loop
		break
	shuffle(switch_list) #shuffle until prerequisites of no repeat of rare condition is met

When I set switch list *= up to 96 the crashes started (earlier it was 8 and worked fine).

Thank you so much

Vincent

Comments

  • I think I figured it out: I'll just generate a new list at the start of every block, so it only needs 24 repetitions instead of 96, that seems to work.

Sign In or Register to comment.