At the start of the experiment, I opened a code component in the Builder to start “Before Experiment”. I’ve written this in Python code:
import random
from datetime import datetime
random.seed(datetime.now())
group = random.randint(1,4)
I need this variable ($group) to have a random (integer) number between 1 and 4. Works perfecty in PsychoPy, but it doesn’t translate into JavaScript. It translates into:
import * as random from 'random';
import {datetime} from 'datetime';
random.seed(datetime.now());
group = random.randint(1, 4);
Of course, this code isn’t recognized. Now, I understand tihs is a previously known problem here. However, I don’t understand the solution perfectly. I don’t fully understand how to write this code (in JS) so that it uses time (or any other form of) seed for randomizing numbers. I’m worried if I don’t seed the random number generator, that every single participant in the study would get the same “random” number in the 1-4 range.
Can anyone help me translate the above Python code into JavaScript so that it gives a different random number (between 1 and 4) to every participant?
Thanks in advance.