You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -156,7 +156,7 @@ Let's use `entropy-string` to help this developer by generating 5 IDs:
156
156
let bits =entropy.bits(10000, 1000000)
157
157
let strings =Array()
158
158
for (let i =0; i <5; i++) {
159
-
let string =entropy.randomString(bits, entropy.charSet16)
159
+
let string =entropy.string(bits, entropy.charSet16)
160
160
strings.push(string)
161
161
}
162
162
```
@@ -172,7 +172,7 @@ To generate the IDs, we first use
172
172
to determine how much entropy is needed to satisfy the probabilistic uniqueness of a **1 in a million** risk of repeat in a total of **10,000** strings. We didn't print the result, but if you did you'd see it's about **45.51** bits. Then inside a loop we used
173
173
174
174
```js
175
-
let string =entropy.randomString(bits, entropy.charSet16)
175
+
let string =entropy.string(bits, entropy.charSet16)
176
176
```
177
177
178
178
to actually generate a random string of the specified entropy using hexadecimal (charSet16) characters. Looking at the IDs, we can see each is 12 characters long. Again, the string length is a by-product of the characters used to represent the entropy we needed. And it seems the developer didn't really need 16 characters after all.
@@ -191,7 +191,7 @@ We'll start with using 32 characters. What 32 characters, you ask? Well, the [Ch
191
191
constentropy=require('entropy-string')
192
192
193
193
let bits =entropy.bits(10000, 1000000)
194
-
let string =entropy.randomString(bits, entropy.charSet32)
194
+
let string =entropy.string(bits, entropy.charSet32)
195
195
```
196
196
197
197
> String: jGjfNbdGQD
@@ -202,15 +202,15 @@ Now let's suppose we need to ensure the names of a handful of items are unique.
Finally, let say we're generating session IDs. We're not interested in uniqueness per se, but in ensuring our IDs aren't predictable since we can't have the bad guys guessing a valid ID. In this case, we're using entropy as a measure of unpredictability of the IDs. Rather than calculate our entropy, we declare it needs to be 128 bits (since we read on some web site that session IDs should be 128 bits).
@@ -281,7 +281,7 @@ Being able to easily generate random strings is great, but what if you want to s
281
281
282
282
```js
283
283
constentropy=require('entropy-string')
284
-
let flips =entropy.randomString(10, entropy.charSet2)
284
+
let flips =entropy.string(10, entropy.charSet2)
285
285
```
286
286
287
287
> flips: 1111001011
@@ -290,7 +290,7 @@ The resulting string of __0__'s and __1__'s doesn't look quite right. Perhaps yo
290
290
291
291
```js
292
292
entropy.charSet2.use('HT')
293
-
flips =entropy.randomString(10, entropy.charSet2)
293
+
flips =entropy.string(10, entropy.charSet2)
294
294
```
295
295
296
296
> flips: THHTHTTHHT
@@ -299,7 +299,7 @@ As another example, we saw in [Character Sets](#CharacterSets) the default chara
299
299
300
300
```js
301
301
entropy.charSet16.use('0123456789ABCDEF')
302
-
let string =entropy.randomString(48, entropy.charSet16)
302
+
let string =entropy.string(48, entropy.charSet16)
303
303
304
304
```
305
305
@@ -308,7 +308,7 @@ As another example, we saw in [Character Sets](#CharacterSets) the default chara
308
308
Or suppose you want a random password with numbers, lowercase letters and special characters.
309
309
310
310
```js
311
-
let password =randomString.entropy(of:64, using: .charSet64)
311
+
let password =string.entropy(of:64, using: .charSet64)
312
312
print("password: \(password)")
313
313
```
314
314
@@ -365,7 +365,7 @@ Compare that to the `entropy-string` scheme. For the example above, slicing off
365
365
366
366
```js
367
367
constentropy=require('entropy-string')
368
-
let string =entropy.randomString(80, entropy.charSet32)
368
+
let string =entropy.string(80, entropy.charSet32)
369
369
```
370
370
371
371
> HFtgHQ9q9fH6B8HM
@@ -376,7 +376,7 @@ However, if you don't need cryptographically strong random strings, you can requ
376
376
377
377
```js
378
378
constentropy=require('entropy-string')
379
-
let string =entropy.randomString(80, entropy.charSet32, false)
379
+
let string =entropy.string(80, entropy.charSet32, false)
380
380
```
381
381
382
382
> fdRp9Q3rTMF7TdFN
@@ -389,24 +389,24 @@ Fortunately you don't need to really understand how the bytes are efficiently sl
389
389
390
390
## <aname="CustomBytes"></a>Custom Bytes
391
391
392
-
As described in [Efficiency](#Efficiency), `entropy-string` automatically generates random bytes using the `crypto` library. But you may have a need to provide your own bytes, say for deterministic testing or to use a specialized byte generator. The `entropy.randomString` function allows passing in your own bytes to create a string.
392
+
As described in [Efficiency](#Efficiency), `entropy-string` automatically generates random bytes using the `crypto` library. But you may have a need to provide your own bytes, say for deterministic testing or to use a specialized byte generator. The `entropy.string` function allows passing in your own bytes to create a string.
393
393
394
394
Suppose we want a string capable of 30 bits of entropy using 32 characters. We pass in 4 bytes (to cover the 30 bits):
395
395
396
396
```js
397
397
constentropy=require('entropy-string')
398
398
399
399
let bytes:RandomString.Bytes=newUint8Array[250, 200, 150, 100]
400
-
let string =entropy.randomString(30, entropy.charSet32, bytes)
400
+
let string =entropy.string(30, entropy.charSet32, bytes)
401
401
```
402
402
403
403
> string: Th7fjL
404
404
405
-
The __bytes__ provided can come from any source. However, the number of bytes must be sufficient to generate the string as described in the [Efficiency](#Efficiency) section. `entropy.randomString` throws an `Error` if the string cannot be formed from the passed bytes.
405
+
The __bytes__ provided can come from any source. However, the number of bytes must be sufficient to generate the string as described in the [Efficiency](#Efficiency) section. `entropy.string` throws an `Error` if the string cannot be formed from the passed bytes.
0 commit comments