ixfx
    Preparing search index...

    Function randomElement

    • Returns a random element of an array

      const v = [`blue`, `red`, `orange`];
      randomElement(v); // Yields `blue`, `red` or `orange`

      Note that repeated calls might yield the same value multiple times. If you want to random unique values, consider using shuffle.

      See also:

      • randomIndex if you want a random index rather than value.

      Type Parameters

      • V

      Parameters

      • array: ArrayLike<V>
      • rand: () => number = Math.random

        Random generator. Math.random by default.

      Returns V