shuffle() function
Fisher-Yates 알고리즘을 사용하여 입력 배열의 요소를 무작위로 섞은 새 배열을 반환합니다.
Signature:
typescript
declare function shuffle<T extends Iterable<unknown> | AsyncIterable<unknown>>(
iterable: T,
seed?: number,
): ReturnArrayType<T>;Example
ts
shuffle([1, 2, 3, 4, 5]); // [3, 1, 5, 2, 4] (random order)
shuffle("hello"); // ["o", "e", "l", "h", "l"] (random order) Only ASCII codes are shuffled in the case of a string.
shuffle([1, 2, 3, 4, 5], 42); // [2, 4, 1, 5, 3] (deterministic with seed 42)