UNPKG

@grandom/shuffle

Version:

A configurable, flexible, seedable, and overall great random shuffler.

52 lines (51 loc) 1.98 kB
import { RandomGenerator, RandomEngine } from '@grandom/core'; export interface ShuffleArrayOptions<T = any> { /** * Filters the input array by element. * * @param element The specific element to filter from the input array. * @returns Whether to keep the specific element in the shuffle pool. */ filter?: (element: T) => boolean; /** * Exclude one or multiple elements from the input array. */ exclude?: T | T[]; } export default class RandomArrayShuffle extends RandomGenerator { constructor(engine: RandomEngine); canBeParsed(arg1: any): boolean; parse(arg1: any, arg2: any, arg3: any): any; /** * Shuffles (mixes) the input array elements randomly and returns them * as a new array (the input array is not modified). * * @param array The array to use to shuffle. */ shuffle<T>(array: ArrayLike<T>): T; /** * Shuffles (mixes) the input array elements randomly and returns them * as a new array (the input array is not modified). * * @param array The array to use to shuffle. * @param count The count (length) of the returned array. */ shuffle<T>(array: ArrayLike<T>, count: number): T; /** * Shuffles (mixes) the input array elements randomly and returns them * as a new array (the input array is not modified). * * @param array The array to use to shuffle. * @param options Shuffle options (filtering and fallback). */ shuffle<T>(array: ArrayLike<T>, options: ShuffleArrayOptions<T>): T; /** * Shuffles (mixes) the input array elements randomly and returns them * as a new array (the input array is not modified). * * @param array The array to use to shuffle. * @param count The count (length) of the returned array. * @param options Shuffle options (filtering and fallback). */ shuffle<T>(array: ArrayLike<T>, count: number, options: ShuffleArrayOptions<T>): T; }