psychopy.org | Reference | Downloads | Github

Random colors without overlapping


#1

Hi guys
I’m trying to build an experiment in which some squares are randomly presented on the left and right side of a fixation cross. I defined a list of colors but I don’t know how to say to python to choose every color not more than once for each array. How can i do it? can someone help me? thanks

#shuffeling of the colors
shuffle(color)
colorright=color[11]
colorleft=color[0]

if condition == 2 or condition == 4 or condition == 6 or condition == 8 or condition==10 or condition == 12 or condition == 14 or condition == 16:
if Cue == 0:
colorleft = color[np.random.randint(1,11)]
colorright=color [11]
if Cue == 1:
colorright = color [np.random.randint(0,10)]
colorleft=color[0]


#2

Usually what you’d do is 1) shuffle your list of values, 2) loop over either that shuffled list (for example for colorright in color) or over some index, then use that index to get your color.

How are you currently doing your trial loop? Psychopy has built-in functions that handle randomising values and looping over them:
http://psychopy.org/api/data.html#trialhandler

There’s an example of that here:


#3

thank you Jan, I’ll try to explain better, what I need is just that color left has a different color from the other presented. this mean that in a list of color like red, brown, pink, blu, yellow, if color right are for example red, blue, yellow (randomly selected) color left is pink (randomly selected). if cue is = color left has to change and the color has to be randomly selected but different from the other randomly selected.