Solution 1 :

processing.js internally uses Math.random() as its internal random number generator. Aside from some additional multiplication steps depending on arguments, they’re essentially the same.

var internalRandomGenerator = function() { return Math.random(); };

p.random = function() {
    if(arguments.length === 0) {
        return internalRandomGenerator();
    if(arguments.length === 1) {
        return internalRandomGenerator() * arguments[0];
    var aMin = arguments[0], aMax = arguments[1];
    return internalRandomGenerator() * (aMax - aMin) + aMin;

Source code

Solution 2 :

With mathematic calculations on a PC it won’t make a noticeable difference whichever you use. Even if you were generating thousands or even millions of random numbers your computer would be able to handle it faster than the blink of an eye.

If speed and/or memory is a major concern then you could try some third party libraries like this, however keep in mind that if memory (as in project size not ram) is a concern then it may be best not to add too many additional modules or libraries.

Problem :

does anyone know whether it is better (memory wise, or faster) to use Math.random() or random() in Khan Academy’s programming environment?

Used “random” as an example, I am reffering to any of the math libraries, really.