UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

23 lines (18 loc) 644 B
import { randomIntegerBetween } from "../../math/random/randomIntegerBetween.js"; import { array_swap_one } from "./array_swap_one.js"; /** * Randomly re-orders items in-place * @template T * @param {function} random * @param {T[]} array */ export function array_shuffle(random, array) { const n = array.length; for (let source_index = 0; source_index < n; ++source_index) { const target_index = randomIntegerBetween(random, 0, n - (source_index + 1)); if (target_index === source_index) { continue; } array_swap_one(array, source_index, target_index); } }