import seedrandom from 'seedrandom' ; import { DataGenerator , RandomNumberGenerator } from '../utils/data_generators/data_generator' ; param obj internal export const forcedType = < T extends Record < string , unknown > > ( obj ) : T => obj as T ; internal export const getRNGSeed = ( fallback ? ) : string | undefined => process . env . RNG_SEED ?? ( process . env . VRT ? 'elastic-charts' : fallback ) ; param string internal export const getRandomNumberGenerator = ( seed = getRNGSeed ( ) ) : RandomNumberGenerator => { const rng = seedrandom ( seed ) ; param { } min param { } max param { } fractionDigits return function randomNumberGenerator ( min = 0 , max = 1 , fractionDigits = 0 , inclusive = true ) { const precision = Math . pow ( 10 , Math . max ( fractionDigits , 0 ) ) ; const scaledMax = max * precision ; const scaledMin = min * precision ; const offset = inclusive ? 1 : 0 ; const num = Math . floor ( rng ( ) * ( scaledMax - scaledMin + offset ) ) + scaledMin ; return num / precision ; } ; } ; internal export class SeededDataGenerator extends DataGenerator { constructor ( frequency = 500 ) { super ( frequency , getRandomNumberGenerator ( ) ) ; } } internal export const getRandomEntryFn = ( seed = getRNGSeed ( ) ) => { const rng = seedrandom ( seed ) ; return function getRandomEntryClosure < T > ( entries ) { if ( Array . isArray ( entries ) ) { const index = Math . floor ( rng ( ) * entries . length ) ; return entries [ index ] ; } const keys = Object . keys ( entries ) ; const index = Math . floor ( rng ( ) * keys . length ) ; const key = keys [ index ] ; return entries [ key ] ; } ; } ;