Example 1 — Official: Shuffle Numbers
Randomize a list of six numbers.
_.shuffle([1, 2, 3, 4, 5, 6]);
// → e.g. [4, 1, 6, 3, 5, 2]
// (order varies each call) How It Works
- Copy first. Underscore works on a new array.
- Fisher-Yates. Each index is swapped with a random earlier/equal index.
- Same members. You still get
1…6, just reordered. - Non-deterministic. Call again for a different permutation.

