@jossmac/lil-libs
    Preparing search index...

    Function randomSampler

    • Creates a function that returns a random sample on each call.

      • T
      • items: T[]

        Source array; captured by the returned function and not mutated.

      • count: number = 1

        Sample size passed to randomSample on each call. Defaults to 1.

      A zero-argument function that returns a fresh random sample each time it is called.

      const items = [1, 2, 3, 4];
      const sampleTwo = randomSampler(items, 2);
      sampleTwo(); // random 2-item sample each call