@@ -11,8 +11,10 @@ export const charset4 = new CharSet('ATCG')
1111export const charset2 = new CharSet ( '01' )
1212
1313const propMap = new WeakMap ( )
14-
1514const BITS_PER_BYTE = 8
15+ const {
16+ ceil, floor, log2, random, round
17+ } = Math
1618
1719const endianByteNum = ( ( ) => {
1820const buf32 = new Uint32Array ( 1 )
@@ -24,8 +26,6 @@ const endianByteNum = (() => {
2426const stringWithBytes = ( bytes , bitLen , charset ) => {
2527if ( bitLen <= 0 ) { return '' }
2628
27- const { floor, ceil} = Math
28-
2929const bitsPerChar = charset . getBitsPerChar ( )
3030const count = ceil ( bitLen / bitsPerChar )
3131if ( count <= 0 ) { return '' }
@@ -56,16 +56,16 @@ const stringWithBytes = (bytes, bitLen, charset) => {
5656return string
5757}
5858
59- const cryptoBytes = count => Buffer . from ( Crypto . randomBytes ( count ) )
59+ const csprngBytes = count => Buffer . from ( Crypto . randomBytes ( count ) )
6060
6161const prngBytes = ( count ) => {
6262const BYTES_USED_PER_RANDOM_CALL = 6
63- const randCount = Math . ceil ( count / BYTES_USED_PER_RANDOM_CALL )
63+ const randCount = ceil ( count / BYTES_USED_PER_RANDOM_CALL )
6464
6565const buffer = Buffer . alloc ( count )
6666const dataView = new DataView ( new ArrayBuffer ( BITS_PER_BYTE ) )
6767for ( let rNum = 0 ; rNum < randCount ; rNum += 1 ) {
68- dataView . setFloat64 ( 0 , Math . random ( ) )
68+ dataView . setFloat64 ( 0 , random ( ) )
6969for ( let n = 0 ; n < BYTES_USED_PER_RANDOM_CALL ; n += 1 ) {
7070const fByteNum = endianByteNum [ n ]
7171const bByteNum = ( rNum * BYTES_USED_PER_RANDOM_CALL ) + n
@@ -79,7 +79,6 @@ const prngBytes = (count) => {
7979
8080const entropyBits = ( total , risk ) => {
8181if ( total === 0 ) { return 0 }
82- const { log2} = Math
8382let N
8483if ( total < 1000 ) {
8584N = log2 ( total ) + log2 ( total - 1 )
@@ -147,7 +146,6 @@ export default class {
147146}
148147
149148let bitLen
150- const { round} = Math
151149if ( params . bits ) {
152150bitLen = round ( params . bits )
153151} else if ( params . total && params . risk ) {
@@ -195,7 +193,7 @@ export default class {
195193
196194string ( bitLen = propMap . get ( this ) . bitLen , charset = propMap . get ( this ) . charset ) {
197195const bytesNeeded = charset . bytesNeeded ( bitLen )
198- const bytes = propMap . get ( this ) . prng ?prngBytes ( bytesNeeded ) :cryptoBytes ( bytesNeeded )
196+ const bytes = propMap . get ( this ) . prng ?prngBytes ( bytesNeeded ) :csprngBytes ( bytesNeeded )
199197return this . stringWithBytes ( bytes , bitLen , charset )
200198}
201199