param { number } min param { number } max returns { number } export function randomInteger ( min , max ) { min = Math . ceil ( min ) ; max = Math . floor ( max ) ; return Math . floor ( Math . random ( ) * ( max - min ) ) + min ; } param collection export function randomIndex < T = any > ( collection ) { return randomInteger ( 0 , collection . length ) ; } param { T [ ] } collection returns { T } export function sample < T > ( collection ) { let result ; if ( Array . isArray ( collection ) ) { result = collection [ randomIndex ( collection ) ] ; } else if ( typeof collection === 'object' ) { const keys = Object . keys ( collection ) ; result = collection [ keys [ randomIndex ( keys ) ] ] ; } return result ; } example param { T [ ] | object } collection param { any [ ] } excluded returns { T } export function sampleWithout < T > ( collection , excluded ) { let result ; do { result = sample ( collection ) ; } while ( excluded . includes ( result ) ) ; return result ; }