import MersenneTwister from 'mersennetwister' ; const mt = new MersenneTwister ( ) ; export function times < T > ( i , times ) { return Array . from ( { length : times } , ( ) => i ) ; } export function sample < T > ( arr ) { return arr [ Math . floor ( mt . random ( ) * arr . length ) ] ; } export function sampleMany < T > ( array , maximum = 1 ) { return shuffle ( array ) . slice ( 0 , maximum ) ; } export function shuffle < T > ( array ) { for ( let i = array . length - 1 ; i > 0 ; i -- ) { const j = Math . floor ( mt . random ( ) * ( i + 1 ) ) ; const temp = array [ i ] ; array [ i ] = array [ j ] ; array [ j ] = temp ; } return array ; } export function compose < T > ( arg , ... fn ) { return fn . reduce ( ( arg , f ) => f ( arg ) , arg ) ; }