@haxall/haxall
    Preparing search index...

    Function randomInt

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

      The range (max - min) must be less than 2**48. min and max must be safe integers.

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

      // Asynchronous
      const {
      randomInt,
      } = await import('node:crypto');

      randomInt(3, (err, n) => {
      if (err) throw err;
      console.log(`Random number chosen from (0, 1, 2): ${n}`);
      });
      // Synchronous
      const {
      randomInt,
      } = await import('node:crypto');

      const n = randomInt(3);
      console.log(`Random number chosen from (0, 1, 2): ${n}`);
      // With `min` argument
      const {
      randomInt,
      } = await import('node:crypto');

      const n = randomInt(1, 7);
      console.log(`The dice rolled: ${n}`);

      Parameters

      • max: number

        End of random range (exclusive).

      Returns number

      v14.10.0, v12.19.0

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

      The range (max - min) must be less than 2**48. min and max must be safe integers.

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

      // Asynchronous
      const {
      randomInt,
      } = await import('node:crypto');

      randomInt(3, (err, n) => {
      if (err) throw err;
      console.log(`Random number chosen from (0, 1, 2): ${n}`);
      });
      // Synchronous
      const {
      randomInt,
      } = await import('node:crypto');

      const n = randomInt(3);
      console.log(`Random number chosen from (0, 1, 2): ${n}`);
      // With `min` argument
      const {
      randomInt,
      } = await import('node:crypto');

      const n = randomInt(1, 7);
      console.log(`The dice rolled: ${n}`);

      Parameters

      • min: number

        Start of random range (inclusive).

      • max: number

        End of random range (exclusive).

      Returns number

      v14.10.0, v12.19.0

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

      The range (max - min) must be less than 2**48. min and max must be safe integers.

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

      // Asynchronous
      const {
      randomInt,
      } = await import('node:crypto');

      randomInt(3, (err, n) => {
      if (err) throw err;
      console.log(`Random number chosen from (0, 1, 2): ${n}`);
      });
      // Synchronous
      const {
      randomInt,
      } = await import('node:crypto');

      const n = randomInt(3);
      console.log(`Random number chosen from (0, 1, 2): ${n}`);
      // With `min` argument
      const {
      randomInt,
      } = await import('node:crypto');

      const n = randomInt(1, 7);
      console.log(`The dice rolled: ${n}`);

      Parameters

      • max: number

        End of random range (exclusive).

      • callback: (err: Error, value: number) => void

        function(err, n) {}.

      Returns void

      v14.10.0, v12.19.0

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

      The range (max - min) must be less than 2**48. min and max must be safe integers.

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

      // Asynchronous
      const {
      randomInt,
      } = await import('node:crypto');

      randomInt(3, (err, n) => {
      if (err) throw err;
      console.log(`Random number chosen from (0, 1, 2): ${n}`);
      });
      // Synchronous
      const {
      randomInt,
      } = await import('node:crypto');

      const n = randomInt(3);
      console.log(`Random number chosen from (0, 1, 2): ${n}`);
      // With `min` argument
      const {
      randomInt,
      } = await import('node:crypto');

      const n = randomInt(1, 7);
      console.log(`The dice rolled: ${n}`);

      Parameters

      • min: number

        Start of random range (inclusive).

      • max: number

        End of random range (exclusive).

      • callback: (err: Error, value: number) => void

        function(err, n) {}.

      Returns void

      v14.10.0, v12.19.0