ixfx
    Preparing search index...

    Function integerSource

    • Returns a function that produces a random integer between max (exclusive) and 0 (inclusive) Use integer if you want a random number directly.

      Invoke directly:

      integerSource(10)();  // Random number 0-9
      

      Or keep a reference to re-compute:

      const r = integerSource(10);
      r(); // Produce a random integer

      If a negative value is given, this is assumed to be the minimum (inclusive), with 0 as the max (inclusive)

      integerSource(-5)();  // Random number from -5 to 0
      

      Specify options for a custom minimum or source of random:

      integerSource({ max: 5,  min: 10 })();  // Random number 4-10
      integerSource({ max: -5, min: -10 })(); // Random number from -10 to -6
      integerSource({ max: 10, source: Math.random })(); // Random number between 0-9, with custom source of random

      Throws an error if max & min are equal

      Parameters

      • maxOrOptions: number | Readonly<{ max: number; min?: number; source?: RandomSource }>

        Max value (exclusive), or set of options

      Returns RandomSource

      Random integer