Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f8abaa9

Browse files
committed
Don’t use bitsWith… functions.
Function to be removed in next major release
1 parent 09f5a97 commit f8abaa9

File tree

8 files changed

+17
-13
lines changed

8 files changed

+17
-13
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Generate a potential of _1 million_ random strings with _1 in a billion_ chance
5151
import {Random, Entropy} from 'entropy-string'
5252

5353
const random = new Random()
54-
const bits = Entropy.bitsWithPowers(6, 9)
54+
const bits = Entropy.bits(1e6, 1e9)
5555

5656
const string = random.string(bits)
5757
```
@@ -63,10 +63,10 @@ See [Real Need](#RealNeed) for description of what entropy bits represents.
6363
`EntropyString` uses predefined `charset32` characters by default (see [Character Sets](#CharacterSets)). To get a random hexadecimal string with the same entropy `bits` as above:
6464

6565
```js
66-
import {Random, Entropy} from 'entropy-string'
66+
import {Random, Entropy, charSet16} from 'entropy-string'
6767

6868
const random = new Random(charSet16)
69-
const bits = Entropy.bitsWithPowers(6, 9)
69+
const bits = Entropy.bits(1e6, 1e9)
7070

7171
const string = random.string(bits)
7272
```
@@ -79,7 +79,7 @@ Custom characters may be specified. Using uppercase hexadecimal characters:
7979
import {Random, Entropy} from 'entropy-string'
8080

8181
const random = new Random('0123456789ABCDEF')
82-
const bits = Entropy.bitsWithPowers(6, 9)
82+
const bits = Entropy.bits(1e6, 1e9)
8383

8484
const string = random.string(bits)
8585
```
@@ -234,13 +234,13 @@ Finally, given that the strings are 12 hexadecimals long, each string actually h
234234

235235
In [Real Need](#RealNeed) our developer used hexadecimal characters for the strings. Let's look at using other characters instead.
236236

237-
We'll start with using 32 characters. What 32 characters, you ask? The [Character Sets](#CharacterSets) section discusses the predefined characters available in `entropy-string` and the [Custom Characters](#CustomCharacters) section describes how you can use whatever characters you want. By default, `entropy-string` uses `charSet32` characters, so we don't need to pass that parameter into `new Random()`. We also use `bitsWithRiskPower` that allows passing the `risk` as a power of 10.
237+
We'll start with using 32 characters. What 32 characters, you ask? The [Character Sets](#CharacterSets) section discusses the predefined characters available in `entropy-string` and the [Custom Characters](#CustomCharacters) section describes how you can use whatever characters you want. By default, `entropy-string` uses `charSet32` characters, so we don't need to pass that parameter into `new Random()`.
238238

239239
```js
240240
import {Random, Entropy} from 'entropy-string'
241241

242242
const random = new Random()
243-
const bits = Entropy.bitsWithRiskPower(10000, 6)
243+
const bits = Entropy.bits(10000, 1e6)
244244
const string = random.string(bits)
245245
```
246246

@@ -277,7 +277,7 @@ Suppose we have a more extreme need. We want less than a 1 in a trillion chance
277277
import {Random, Entropy} from 'entropy-string'
278278

279279
const random = new Random()
280-
const bits = Entropy.bitsWithPowers(10, 12)
280+
const bits = Entropy.bits(1e10, 1e12)
281281
const string = random.string(bits)
282282
```
283283

@@ -516,7 +516,7 @@ Note the number of bytes needed is dependent on the number of characters in our
516516
import {Random, Entropy} from 'entropy-string'
517517

518518
const random = new Random()
519-
const bits = Entropy.bitsWithPowers(6,9)
519+
const bits = Entropy.bits(1e6,1e9)
520520
const string = random.string(bits)
521521
```
522522

dist/lib/entropy.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,13 @@ var bits = function bits(total, risk) {
4444
return _totalOf(total, _log2(risk));
4545
};
4646

47+
// CxTBD Mark as obsolete
4748
var bitsWithRiskPower = function bitsWithRiskPower(total, rPower) {
4849
var log2Risk = _log2_10 * rPower;
4950
return _totalOf(total, log2Risk);
5051
};
5152

53+
// CxTBD Mark as obsolete
5254
var bitsWithPowers = function bitsWithPowers(tPower, rPower) {
5355
var N = 0;
5456
if (tPower < 4) {

examples/more_3.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import {Random, Entropy} from './entropy-string'
44

55
const random = new Random()
6-
const bits = Entropy.bitsWithPowers(10, 12)
6+
const bits = Entropy.bits(1e10, 1e12)
77
const string = random.string(bits)
88

99
console.log('\n Ten billion potential strings with 1 in a trillion risk of repeat: ' + string + '\n')

examples/tldr2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import {Random, Entropy} from './entropy-string'
44

55
const random = new Random()
6-
const bits = Entropy.bitsWithPowers(6,9)
6+
const bits = Entropy.bits(1e6,1e9)
77
const string = random.string(bits)
88

99
console.log('\n Base32 string with a 1 in a billion chance of repeat in a million strings: ' + string + '\n')

examples/tldr_1.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import {Random, Entropy} from './entropy-string'
44

55
const random = new Random()
6-
const bits = Entropy.bitsWithPowers(6, 9)
6+
const bits = Entropy.bits(1e6, 1e9)
77

88
const string = random.string(bits)
99

examples/tldr_2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import {Random, Entropy, charSet16} from './entropy-string'
55

66
const random = new Random(charSet16)
7-
const bits = Entropy.bitsWithPowers(6, 9)
7+
const bits = Entropy.bits(1e6, 1e9)
88

99
const string = random.string(bits)
1010

examples/tldr_3.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import {Random, Entropy} from './entropy-string'
44

55
const random = new Random('0123456789ABCDEF')
6-
const bits = Entropy.bitsWithPowers(6, 9)
6+
const bits = Entropy.bits(1e6, 1e9)
77

88
const string = random.string(bits)
99

lib/entropy.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ const bits = (total, risk) => {
2323
return _totalOf(total, _log2(risk))
2424
}
2525

26+
// CxTBD Mark as obsolete
2627
const bitsWithRiskPower = (total, rPower) => {
2728
let log2Risk = _log2_10 * rPower
2829
return _totalOf(total, log2Risk)
2930
}
3031

32+
// CxTBD Mark as obsolete
3133
const bitsWithPowers = (tPower, rPower) => {
3234
let N = 0
3335
if (tPower < 4) {

0 commit comments

Comments
 (0)