Code coverage report for random/randInt.js

Statements: 100% (7 / 7)      Branches: 100% (4 / 4)      Functions: 100% (3 / 3)      Lines: 100% (6 / 6)     

All files » random/ » randInt.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 171         1 2366 2366       2366     1    
define(['../number/MIN_INT', '../number/MAX_INT', './rand'], function(MIN_INT, MAX_INT, rand){
 
    /**
     * Gets random integer inside range or snap to min/max values.
     */
    function randInt(min, max){
        min = min == null? MIN_INT : ~~min;
        max = max == null? MAX_INT : ~~max;
        // can't be max + 0.5 otherwise it will round up if `rand`
        // returns `max` causing it to overflow range.
        // -0.5 and + 0.49 are required to avoid bias caused by rounding
        return Math.round( rand(min - 0.5, max + 0.499999999999) );
    }
 
    return randInt;
});