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

Function pickOne

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

Source from the content-addressed store, hash-verified

42 * @returns @zh 随机元素 @en Random element
43 */
44export function pickOne<T>(array: readonly T[], rng: SeededRandom | { next(): number }): T {
45 if (array.length === 0) {
46 throw new Error('Cannot pick from empty array');
47 }
48 return array[Math.floor(rng.next() * array.length)];
49}
50
51/**
52 * @zh 从数组中随机采样 N 个不重复元素

Callers 2

executeMethod · 0.90
sampleWithReplacementFunction · 0.85

Calls 1

nextMethod · 0.80

Tested by

no test coverage detected