Skip to content

Commit 23b8ab5

Browse files
committed
Run examples
1 parent 05b9a21 commit 23b8ab5

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,9 @@ Efficiently generate cryptographically strong random strings of specified entrop
3434

3535
### <a name="TLDR"></a>TL;DR
3636

37-
##### Examples
38-
39-
Run the examples file using
40-
41-
```bash
42-
yarn examples
43-
node dist/examples.js
44-
```
45-
4637
##### Example Usage
4738

48-
OWASP session ID using base32 characters:
39+
OWASP session ID using base 32 characters:
4940
```js
5041
import {Random} from 'entropy-string'
5142

@@ -112,6 +103,15 @@ Base 64 character string with a 1 in a trillion chance of a repeat in 100 millio
112103

113104
> emzRPXRudAjZnOme
114105
106+
##### Examples
107+
108+
Run any of the examples in the `examples` directory by:
109+
110+
```bash
111+
yarn examples
112+
node examples/dist/tldr.js
113+
```
114+
115115
[TOC](#TOC)
116116

117117
### <a name="Overview"></a>Overview
@@ -398,7 +398,7 @@ The 3rd option above will throw an `Error` if the characters string isn't approp
398398

399399
### <a name="Efficiency"></a>Efficiency
400400

401-
To efficiently create random strings, `entropy-string` generates the necessary number of bytes needed for each string and uses those bytes in a bit shifting scheme to index into a character set. For example, consider generating strings from the `base32` character set. There are __32__ characters in the set, so an index into an array of those characters would be in the range `[0,31]`. Generating a random string of `base32` characters is thus reduced to generating a random sequence of indices in the range `[0,31]`.
401+
To efficiently create random strings, `entropy-string` generates the necessary number of bytes needed for each string and uses those bytes in a bit shifting scheme to index into a character set. For example, consider generating strings from the `charSet32` character set. There are __32__ characters in the set, so an index into an array of those characters would be in the range `[0,31]`. Generating a random string of `charSet32` characters is thus reduced to generating a random sequence of indices in the range `[0,31]`.
402402

403403
To generate the indices, `entropy-string` slices just enough bits from the array of bytes to create each index. In the example at hand, 5 bits are needed to create an index in the range `[0,31]`. `entropy-string` processes the byte array 5 bits at a time to create the indices. The first index comes from the first 5 bits of the first byte, the second index comes from the last 3 bits of the first byte combined with the first 2 bits of the second byte, and so on as the byte array is systematically sliced to form indices into the character set. And since bit shifting and addition of byte values is really efficient, this scheme is quite fast.
404404

@@ -447,7 +447,7 @@ Fortunately you don't need to really understand how the bytes are efficiently sl
447447

448448
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 `random.string` function allows passing in your own bytes to create a string.
449449

450-
Suppose we want a string capable of 30 bits of entropy using 32 characters. We pass in 4 bytes to cover the 30 bits needed to generate 6 base32 characters:
450+
Suppose we want a string capable of 30 bits of entropy using 32 characters. We pass in 4 bytes to cover the 30 bits needed to generate six base 32 characters:
451451

452452
```js
453453
import {Random} from 'entropy-string'

0 commit comments

Comments
 (0)