import { bitLength } from 'bigint-mod-arith' ; import { fromBuffer } from './fromBuffer' ; import { randBitsSync } from './randBits' ; param max param min throws returns export function randBetween ( max , min = 1n ) { if ( max <= min ) throw new RangeError ( 'Arguments MUST be: max > min' ) ; const interval = max - min ; const bitLen = bitLength ( interval ) ; let rnd ; do { const buf = randBitsSync ( bitLen ) ; rnd = fromBuffer ( buf ) ; } while ( rnd > interval ) ; return rnd + min ; }