WLJS LogoWLJS Notebook

RandomSample

RandomSample[{e1, e2, ...}, n] gives a pseudorandom sample of n elements (without replacement).

RandomSample[{e1, e2, ...}] gives a pseudorandom permutation of the elements.

Examples

Random sample without replacement:

RandomSample[{1, 2, 3, 4, 5}, 3]
(* {3, 5, 1} *)

Random permutation:

RandomSample[{a, b, c, d}]
(* {c, a, d, b} *)

Please visit the official Wolfram Language Reference for more details.

On this page