Translating random.normal to JS

URL of experiment: https://gitlab.pavlovia.org/kennethj/variable-interval

Description of the problem: I’ve created an experiment in Builder that includes a Code Component. The code I am struggling with is as follows: VI = normal(loc=20, scale=10.0)

I need to randomly sample numbers, with a specified mean (loc) and standard deviation (scale), from a normal distribution. The Code Component works in Builder, but does not work online (i.e., I get an error that ‘normal’ is not defined). Auto->JS does not know what to do with ‘random.normal’ and I do not know how to translate it to JS.

Does anyone know how to translate this code to JS?

If I were you I would create a large array of Z scores in Excel, load them into an array, and then shuffle to select a random number.

There are some clever math tricks to allow you to use Math.random to produce a gaussian distribution instead of its typical uniform one. https://stackoverflow.com/questions/25582882/javascript-math-random-normal-distribution-gaussian-bell-curve/36481059#36481059