@mirei/ts-collections
    Preparing search index...

    Function shuffle

    • Returns a deferred sequence whose elements appear in random order.

      Type Parameters

      • TElement

        Type of elements within the source iterable.

      Parameters

      • source: Iterable<TElement>

        The source iterable.

      Returns IEnumerable<TElement>

      A sequence containing the same elements as source but shuffled.

      The implementation materialises the entire sequence into an array before shuffling, making this unsuitable for infinite sequences.

      const numbers = [1, 2, 3, 4, 5];
      const shuffled = shuffle(numbers).toArray();
      console.log(shuffled); // e.g., [3, 1, 5, 2, 4]