Sha256: 56efd8c3508541e8c0f7b02c19bb12cce3323ba63df09f394d0c4f76548c0c9e
Contents?: true
Size: 593 Bytes
Versions: 69
Compression:
Stored size: 593 Bytes
Contents
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; });
Version data entries
69 entries across 69 versions & 2 rubygems