(array: readonly T[], rng: SeededRandom | { next(): number })
| 42 | * @returns @zh 随机元素 @en Random element |
| 43 | */ |
| 44 | export 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 个不重复元素 |
no test coverage detected