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

    Function randomSample

    • Returns a random subset of items without mutating the source array.

      Defaults to count = 1. Returns [] when count is 0, and all items when count equals the array length.

      • T
      • items: T[]

        Source array; not mutated.

      • count: number = 1

        Number of items to take after shuffling. Defaults to 1; 0 returns [], and values equal to items.length return all items.

      A new array of up to count items in random order (via randomShuffle).

      const items = ["a", "b", "c", "d"];
      randomSample(items, 2); // e.g. ["d", "a"]
      randomSample(items); // e.g. ["b"] (default count: 1)
      randomSample(items, 0); // []
      randomSample(items, items.length); // all items, shuffled