Easiest way to select one of four numbers randomly in an online Experiment

I want to randomise the orientation of my stimuli, I can do this through python by simply

import random
a = [90,180,270,360]
LetterOri = (random.choice(a))

However I know this will not work online, as you can’t import packages online.

Is there I way I can do this without relying on the random package?

This should help you: Get a random item from a JavaScript array - Stack Overflow


why not

ori = [90,180,270,360]
orientation = ori.pop()

You might need to change manually




, see

You posted in Online experiments, so I assume that you will run the experiment online. Do not import libraries (e.g. import random). That will not work online.The Builder will import all libraries for which there are PsychoJS counterparts.

Best wishes Jens

1 Like

Hi Jens,

Thank you so much!

Yeah I’ve had issues in the past where I built my experiment using import random, then found it wouldn’t work online. So I definitely learned my lesson there.

Kind regards,