javascript-collections-framework
    Preparing search index...

    Function shuffle

    • Puts the elements of list in a random order, in place, using the Fisher–Yates method: every permutation is equally likely when random is uniform. random is called max(size − 1, 0) times and must return a number in [0, 1); pass a seeded generator for a repeatable order. The default, Math.random, is not cryptographically secure. Elements are written with set, so open iterators and cursors stay valid.

      Time: O(n).

      Parameters

      • list: List<unknown>

        The list to shuffle.

      • Optionalrandom: () => number

        Returns numbers in [0, 1); Math.random when omitted.

      Returns void

      TypeError when list is not a list from this library, random is not a function, or it returns a non-number.

      IllegalArgumentError when random returns NaN or a value outside [0, 1); the swaps made before stay.

      ConcurrentModificationError when random changes the list.

      Error whatever random throws; the swaps made before stay.

      const deck = new ArrayList(['a', 'b', 'c'])
      shuffle(deck)