Write a truly inclusive random method for javascript

This will return [0,1] inclusive:

if(MATH.random() == 0)
    return 1;
else
    return MATH.random();

Explanation: If the first call to random() returns 0, return 1. Otherwise, call random again, which will be [0,1). Therefore, it will return [0,1] all inclusive.

Leave a Comment