I have a list of stimuli, where each item is either congruent or incongruent (cond CO or IN) and each item is of type A, B or C (type A, B C)
item 1: CO, A
item 2: IN, A
item 3: CO, B
item 4: IN, C
I want to pseudo-randomize the order of this stimuli list so that:
1) the same type (A,B,C) does not repeat (e.g., I don’t want A,A,… or B,B,…) in a row
and at the same time so that:
2) the same cond (CO, IN) does not repeat more than twice in a row (e.g., CO,CO,CO, IN, IN, IN, …)
I have always used this handy randomization function to fulfill the first condition.
My question is: How could the function be modified to fulfill both conditions at the same time:
# RANDOMIZATION FUNCTIONS #helper function for standard_randomization (Given a list, find first pair that does not contain given condition.) def find_indelst, condition): a = 'a' b = 'b' idx = 0 while a != b and idx < len(lst): a = idx b = idx+1 idx += 1 # assuming pair is always found!! it might not be the case return idx+1 #Randomization function (input: a list of dictionaries, returns a randomized list) def standard_randomization(lst): randomized_lst =  pre_item = '' # first item item = lst.pop(lst.inderandom.choice(lst)))# get a random item from list randomized_lst.append(item) pre_cond = item[CONDITION] while len(lst) > 1: item = lst.pop(lst.inderandom.choice(lst))) if pre_cond == item[CONDITION]: lst.append(item) else: randomized_lst.append(item) pre_cond = item[CONDITION] # check that n and n-1 are not the same item = lst if pre_cond != item[CONDITION]: randomized_lst.append(item) # find place to insert last item if they are else: idx = find_inderandomized_lst, item[CONDITION]) randomized_lst.insert(idx, item) return randomized_lst
I have thought of adding the CONDITION2 into this function and checking for pre-cond and pre.pre-cond item for the second cond. Does anyone have more elegant idea how to go around it?
Thanks for any suggestions,