Sha256: 10122e890eabb5562750cfa140f1decc73b44ce544a9acd1affc2b6946d84606

Contents?: true

Size: 623 Bytes

Versions: 69

Compression:

Stored size: 623 Bytes

Contents

var MIN_INT = require('../number/MIN_INT');
var MAX_INT = require('../number/MAX_INT');
var rand = require('./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) );
    }

    module.exports = randInt;

Version data entries

69 entries across 69 versions & 2 rubygems

Version Path
trusty-festivity-extension-2.6.3 node_modules/bower/node_modules/mout/random/randInt.js
trusty-festivity-extension-2.6.2 node_modules/bower/node_modules/mout/random/randInt.js
trusty-festivity-extension-2.6.1 node_modules/bower/node_modules/mout/random/randInt.js
trusty-festivity-extension-2.6 node_modules/bower/node_modules/mout/random/randInt.js
trusty-festivity-extension-2.5.19 node_modules/bower/node_modules/mout/random/randInt.js
trusty-festivity-extension-2.5.18 node_modules/bower/node_modules/mout/random/randInt.js
trusty-festivity-extension-2.5.17 node_modules/bower/node_modules/mout/random/randInt.js
trusty-festivity-extension-2.5.16 node_modules/bower/node_modules/mout/random/randInt.js
trusty-festivity-extension-2.5.15 node_modules/bower/node_modules/mout/random/randInt.js
trusty-festivity-extension-2.5.14 node_modules/bower/node_modules/mout/random/randInt.js
trusty-festivity-extension-2.5.13 node_modules/bower/node_modules/mout/random/randInt.js
trusty-festivity-extension-2.5.12 node_modules/bower/node_modules/mout/random/randInt.js
trusty-festivity-extension-2.5.11 node_modules/bower/node_modules/mout/random/randInt.js
trusty-festivity-extension-2.5.10 node_modules/bower/node_modules/mout/random/randInt.js
trusty-festivity-extension-2.5.9 node_modules/bower/node_modules/mout/random/randInt.js
trusty-festivity-extension-2.5.8 node_modules/bower/node_modules/mout/random/randInt.js
trusty-festivity-extension-2.5.7 node_modules/bower/node_modules/mout/random/randInt.js
trusty-festivity-extension-2.5.6 node_modules/bower/node_modules/mout/random/randInt.js
trusty-festivity-extension-2.5.5 node_modules/bower/node_modules/mout/random/randInt.js
trusty-festivity-extension-2.5.4 node_modules/bower/node_modules/mout/random/randInt.js