Randomize participants in online studies

Hello,
I would like to use an experiment in Pavlovia that I created in Psychopy. Here, subjects are to respond to orange and blue colors with response keys (d and k). I want the key d to be orange for some subjects (orange_key_response) and blue for other subjects, this should be randomized. Normally I would use the import random command, but that doesn’t work for online studies (at least not for me). Are there any alternative solutions?

You didn’t say how you did this in psychopy, but for pavlovia you would search for ‘random number in javascript’.
If you want it to be random across participants:

if ((Math.random() <= 0.5)) {
    orange_key_response = 'd';
    blue_key_response = 'k'
} else {
    orange_key_response = 'k';
    blue_key_response = 'd'
}

Math.random() will give you a float between 0 and 1. If you want an even probability of each mapping you would use less than or greater than .5 for one option and otherwise the other option.

if you want it to alternate across participants, you would first need to set a variable to the participant ID, subNum = expInfo['participant']. Then if the modulus (%, i.e., the remainder after dividing by a number) is 1 use one option, otherwise use the other option. As long as your participant IDs are incremental you’ll end up with even numbers of each mapping, at least before data trimming.

if (((Number.parseInt(subNum) % 2) === 1)) {
    orange_key_response = 'd';
    blue_key_response = 'k'
} else {
    orange_key_response = 'k';
    blue_key_response = 'd'
}

I assume you had code for this in a ‘Begin Experiment’ code component, but if not, you should put this code there, and set the code type to ‘Both’ not ‘Auto-> JS’.