Hi everyone,
I noticed a problem with random number generation.
I am assigning a random list at the start of the experiment, and use the autoTranslate option
from python to JavaScript. Here is the code:
Python:
myLists = (“List1.xlsx”,“List2.xlsx”,“List3.xlsx”,“List4.xlsx”)
myChoice = randint(0,3)
listFile = myLists[myChoice]
JavaScript (auto-translated):
myLists = [“List1.xlsx”, “List2.xlsx”, “List3.xlsx”, “List4.xlsx”];
myChoice = (Math.floor((Math.random() * ((3 - 0) + 1))) + 0);
listFile = myLists[myChoice];
Both codes work, but lead to different results. If I do a test experiment, which draws 200 numbers,
in Python I get the following distribution:
table(myData$chosenList)
List1.xlsx List2.xlsx List3.xlsx
64 66 70
Which seems to indicate that, contrary to how randint is described, it is not inclusive (i.e., randint(0,3) only returns the option 0,1,2, but not 3. Or is there a different version of randint built into psychopy that differs from the (Math.)randint function?
However, online in piloting mode, I get:
table(myData$chosenList)
List1.xlsx List2.xlsx List3.xlsx List4.xlsx
44 52 49 55
Which indicates that (as intended) all four lists are chosen. Obviously, I want to make sure that this works,
because otherwise, I will be paying participants for nothing. I tried to change the code, so that I have similar steps in both, but ran into the problem that I could not call a floor function in PsychoPy (and I am not sure how autoTranslate will work, if I start using an import Math statement at the start of the experiment).
Sincerely,
Holger