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.

Try Pick Random in Calcul.io

Start with one of the editable examples above, then replace its arguments with your own values. Keeping the function on a separate calculator line makes the input and result easy to compare. For a longer workflow, assign the result to a variable or reference that line in the next expression.

Check the shown signature before adding optional arguments, and use the related-function links to compare operations with similar purposes.

All functions