• min {integer} Start of random range (inclusive). Default: 0.
    • max {integer} End of random range (exclusive).
    • callback {Function} function(err, n) {}.

    Return a random integer n such that min <= n < max. This implementation avoids [modulo bias][].

    The range (max - min) must be less than 248. min and max must be [safe integers][].

    If the callback function is not provided, the random integer is generated synchronously.

    1. // Asynchronous
    2. crypto.randomInt(3, (err, n) => {
    3. if (err) throw err;
    4. console.log(`Random number chosen from (0, 1, 2): ${n}`);
    5. });
    1. // Synchronous
    2. const n = crypto.randomInt(3);
    3. console.log(`Random number chosen from (0, 1, 2): ${n}`);
    1. // With `min` argument
    2. const n = crypto.randomInt(1, 7);
    3. console.log(`The dice rolled: ${n}`);