randomGaussian() definition

In the randomGaussian() definition, the variable y2 is never declared. Is that an oversight? Or is it deliberate and I’m missing something. Thanks in advance.

https://github.com/processing/p5.js/blob/1.3.1/src/math/random.js#L153

y2 is declared on line 20.

EDIT (May 26, 2021):

Note that it is global, and therefore retains a value between function calls. It is initialized at a value of 0.

Since it is global, and its value is changed on line 222, whenever randomGaussian() executes, it maintains a state that enables that function to give us a different result each time it is called.

Line 20:

let y2 = 0;

Line 222 (inside the function):

    y2 = x2 * w;
3 Likes

Thanks. I was focused on the inside of the function that I didn’t see it all the way at the beginning.

1 Like