pickRandom

pickRandom(array)

pickRandom(array, number)

pickRandom(array, weights)

pickRandom(array, number, weights)

pickRandom(array, weights, number)

Try it yourself:

See also:

pickRandom(): choose a random item

pickRandom(collection) selects an item at random from a collection. It is handy for sampling, simulations, randomized examples, and simple games.

Sampling considerations

One call returns one selection; repeated calls may choose the same item again. For sampling without replacement, remove selected items or use a dedicated sampling workflow.

Related random tools

Use random() for numeric random values, randomInt() for integer ranges, and sort() to randomize an entire list. size() checks the candidate count.

Caveat

An empty collection cannot supply an item. Do not use ordinary random selection where cryptographic unpredictability is required.

All functions