Implementation of the Fisher-Yates shuffle algorithm in JavaScript, with the possibility of using a seed to ensure reproducibility.
(require("knuth-shuffle-seeded"))(array, seedopt) → {Array}
Shuffle an array using the Fisher-Yates shuffle algorithm, aka Knuth shuffle.
Note that this function overwrites the initial array. As a result if you would like to keep the original array intact, you have to copy the initial array to a new array.
Implementation derived from http://stackoverflow.com/questions/2450954/.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
array |
Array | An array that is to be shuffled. |
||
seed |
<optional> |
Math.random() | Seed for the shuffling operation. If unspecified then a random value is used. |
Returns:
The resulting array.
- Type
- Array