packageDocumentation module NOTE param { Number } bytes return { String } export const randomBytes = ( bytes ) : string => { let randBz ; if ( typeof window !== 'undefined' && window . crypto && window . crypto . getRandomValues ) { randBz = window . crypto . getRandomValues ( new Uint8Array ( bytes ) ) ; } else if ( typeof require !== 'undefined' ) { randBz = require ( 'crypto' ) . randomBytes ( bytes ) ; } else { throw new Error ( 'Unable to generate safe random numbers.' ) ; } let randStr = '' ; for ( let i = 0 ; i < bytes ; i += 1 ) { randStr += `00${ randBz [ i ] . toString ( 16 ) }` . slice ( - 2 ) ; } return randStr ; } ;