psychopy.org | Reference | Downloads | Github

Randomize color of stimuli

OS (e.g. Win10): Win 10
PsychoPy version (e.g. 1.84.x): 2021.1.4
Standard Standalone? (y/n) If not then what?: Y
What are you trying to achieve?:

So I have 34 pairs of words that currently are pre-defined as to what color they should be. I am working on an alternate version of this where the code should randomly pick between set colors. How can this be achieved? I want the code to pick between the colors Red, Blue, and Green.

Should I try something like ‘random(blue, green, red)’ in the foreground color? Does something like this have to be added after it is compiled to Python?

Thank you in advance!

You’re close with random, if you compile :compile_py: to Python you’ll see at the beginning of the code that it imports various functions from numpy.random - the one you’ll want is randchoice. This should work:

$randchoice(['blue', 'green', 'red'])