MCPcopy Create free account
hub / github.com/esengine/esengine / shuffle

Function shuffle

packages/procgen/src/random/Shuffle.ts:16–22  ·  view source on GitHub ↗
(array: T[], rng: SeededRandom | { next(): number })

Source from the content-addressed store, hash-verified

14 * @returns @zh 洗牌后的数组(同一数组)@en Shuffled array (same array)
15 */
16export function shuffle<T>(array: T[], rng: SeededRandom | { next(): number }): T[] {
17 for (let i = array.length - 1; i > 0; i--) {
18 const j = Math.floor(rng.next() * (i + 1));
19 [array[i], array[j]] = [array[j], array[i]];
20 }
21 return array;
22}
23
24/**
25 * @zh 创建洗牌后的副本(不修改原数组)

Callers 2

executeMethod · 0.90
shuffleCopyFunction · 0.85

Calls 1

nextMethod · 0.80

Tested by

no test coverage detected