import type { TypedArray } from "@thi.ng/api" ; import { assert } from "@thi.ng/errors/assert" ; import type { IRandom } from "@thi.ng/random" ; import { SYSTEM } from "@thi.ng/random/system" ; import type { AnyArray } from "./api.js" ; remarks If neither `start` / `end` are given, the entire array will be
 * shuffled. Mutates original array.
 *
 * See  {@link @thi.ng/random#IRandom} param buf param n param rnd export const shuffleRange = < T extends AnyArray > ( buf , start = 0 , end = buf . length , rnd = SYSTEM ) => { assert ( start >= 0 && end >= start && end <= buf . length , `illegal range ${ start }..${ end }` ) ; if ( end - start > 1 ) { for ( let i = end ; i -- > start ; ) { const a = rnd . minmax ( start , i + 1 ) | 0 ; const t = buf [ a ] ; buf [ a ] = buf [ i ] ; buf [ i ] = t ; } } return buf ; } ; /**
 * Applies  shuffleRange to the given array. If `n` is given,
 * only the first `n` items are shuffled. Mutates original array.
 *
 *  shuffleRange param buf param n param rnd export const shuffle = < T extends any [ ] | TypedArray > ( buf , n = buf . length , rnd = SYSTEM ) => shuffleRange ( buf , 0 , n , rnd ) ;