ixfx
    Preparing search index...

    Function integerUniqueGen

    • Returns a generator over random unique integers, up to but not including the given max value.

      Parameters

      Returns IterableIterator<number>

      const rand = [ ...integerUniqueGen(10) ];
      // eg: [2, 9, 6, 0, 8, 7, 3, 4, 5, 1]
      // 5..9 range
      const rand = [ ...integerUniqueGen({ min: 5, max: 10 })];

      Range can be looped. Once the initial random walk through the number range completes, it starts again in a new random way.

      for (const r of integerUniqueGen({ max: 10, loop: true })) {
      // Warning: loops forever
      }

      Behind the scenes, an array of numbers is created that captures the range, this is then shuffled on the first run, and again whenever the iterator loops, if that's allowed.

      As a consequence, large ranges will consume larger amounts of memory.