shuffle

shuffle(array array)
Randomly shuffles an array.

Shuffles a list randomly.

Example:

var numbers = [1, 2, 3, 4, 5]
shuffle(numbers)
debug(numbers) // [4, 1, 2, 5, 3] for example
const numbers = [1, 2, 3, 4, 5]
// Fisher-Yates shuffle. Math.random is seeded with the fight's seed:
// replaying the fight gives the same shuffle.
for (let i = numbers.length - 1; i > 0; i--) {
	const j = Math.floor(Math.random() * (i + 1));
	[numbers[i], numbers[j]] = [numbers[j], numbers[i]]
}
Debug.log(numbers) // [4, 1, 2, 5, 3] for example
import random
numbers = [1, 2, 3, 4, 5]
# random is seeded with the fight's seed: replaying the fight gives the same shuffle.
random.shuffle(numbers)
Debug.log(numbers)  # [4, 1, 2, 5, 3] for example
Parameters