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
Copy file name to clipboardExpand all lines: README.md
+42-11Lines changed: 42 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,6 +25,7 @@ Simple, flexible and efficient generation of probably unique identifiers (`puid`
25
25
-[ID randomness](#IDRandomness)
26
26
-[Efficiency](#Efficiency)
27
27
-[Overkill and Under Specify](#Overkill)
28
+
-[Efficiencies](#Efficiencies)
28
29
-[tl;dr](#tl;dr)
29
30
30
31
## <aname="Overview"></a>Overview
@@ -255,7 +256,7 @@ Rather, a random string represents _captured_ entropy, entropy that was produced
255
256
// => '18f6303a'
256
257
```
257
258
258
-
In this case, the entropy of the string **`'18f6303a'`** is 1 bit. That's it; 1 bit. The same entropy as when the outcome **`'1'`** is observed. In either case, there are only two possible, equally likely outcomes and the resulting entropy is therefore 1 bit. It's important to have this clear understanding:
259
+
In this case, the entropy of the string **`'18f6303a'`** is 1 bit. That's it; 1 bit. The same entropy as when the outcome **`'1'`** is observed. In either case, there are only two equally possible outcomes and the resulting entropy is therefore 1 bit. It's important to have this clear understanding:
259
260
260
261
> _**Entropy is a measure in the uncertainty of an event, independent of the representation of that uncertainty**_
261
262
@@ -339,7 +340,7 @@ First, consider the amount of source entropy used in the code above. The JavaScr
339
340
340
341
Second, consider how much entropy was captured by the ID. Given there are 26 characters, each character represents log<sub>2</sub>(26) = 4.7 bits of entropy. So each generated ID represents 8 * 4.7 = 37.6 bits of entropy.
341
342
342
-
Hmmmm. That means the ratio of ID entropy to source entropy is 37.6 / 464 = 0.09, or a whopping **9%**. That's not an efficiency most developers would be comfortable with. Granted, this is a particularly egregious example, but most random ID generation suffers such inefficient use of source entropy.
343
+
Hmmmm. That means the ratio of ID entropy to source entropy is 37.6 / 424 = 0.09, or a whopping **9%**. That's not an efficiency most developers would be comfortable with. Granted, this is a particularly egregious example, but most random ID generation suffers such inefficient use of source entropy.
343
344
344
345
Without delving into the specifics (see the code?), `puid-js` employs various means to maximize the use of source entropy. In comparison, `puid-js` uses **87.5%** of source entropy in generating random IDs using lower case alpha characters. For character sets with counts equal a power of 2, `puid-js` uses 100% of source entropy.
345
346
@@ -349,7 +350,7 @@ As previous noted, the entropy of a random string is equal to the entropy per ch
349
350
350
351
<aname="UUIDCharacters"></a>
351
352
352
-
However, the total entropy of a string is the product of the entropy per character times the string length *only* if each character in the final string is equally probable. This is always the case for `puid-js`, and is usually the case for other random string generators. There is, however, a notable exception: the version 4 string representation of a `uuid`. As defined in [RFC 4122, Section 4.4](https://tools.ietf.org/html/rfc4122#section-4.4), a v4 `uuid` uses a total of 32 hex and 4 hyphen characters. Although the hex characters can represent 4 bits of entropy each, 6 bits of the hex representation in a `uuid` are actually fixed, so there is only `32*4 - 6 = 122`-bits of entropy (not 128). The 4 fixed-position hyphen characters contribute zero entropy. So a 36 character `uuid` has an `ere` of `122 / (36*8) = 0.40`, or **40%**. Compare that to, say, the default `puid-js` generator, which has slightly higher entropy (128 bits) and yet yields an `ere` of 0.75, or **75%**. Who doesn't love efficiency?
353
+
The total entropy of a string is the product of the entropy per character times the string length *only* if each character in the final string is equally probable. This is always the case for `puid-js`, and is usually the case for other random string generators. There is, however, a notable exception: the version 4 string representation of a `uuid`. As defined in [RFC 4122, Section 4.4](https://tools.ietf.org/html/rfc4122#section-4.4), a v4 `uuid` uses a total of 32 hex and 4 hyphen characters. Although the hex characters can represent 4 bits of entropy each, 6 bits of the hex representation in a `uuid` are actually fixed, so there is only `32*4 - 6 = 122`-bits of entropy (not 128). The 4 fixed-position hyphen characters contribute zero entropy. So a 36 character `uuid` has an `ere` of `122 / (36*8) = 0.40`, or **40%**. Compare that to, say, the default `puid-js` generator, which has slightly higher entropy (128 bits) and yet yields an `ere` of 0.75, or **75%**. Who doesn't love efficiency?
353
354
354
355
[TOC](#TOC)
355
356
@@ -391,28 +392,58 @@ Hmmm. Looks like there are 500,000 IDs expected and the repeat risk is 1 in a tr
391
392
392
393
[TOC](#TOC)
393
394
395
+
### <aname="Efficiencies"></a>Efficiencies
396
+
397
+
`Puid` employs a number of efficiencies for random ID generation:
398
+
399
+
- Only the number of bytes necessary to generate the next `puid` are fetched from the entropy source
400
+
- Each `puid` character is generated by slicing the minimum number of bits possible
401
+
- Any left-over bits are carried forward and used in generating the next `puid`
402
+
- All characters are equally probable to maximize captured entropy
403
+
- Only characters that represent entropy are present in the final ID
404
+
- Easily specified `total/risk` ensures ID are only as long as actually necessary
405
+
406
+
[TOC](#TOC)
407
+
394
408
### <aname="tl;dr"></a>tl;dr
395
409
396
-
`puid-js` is a simple, flexible and efficient random ID generator:
410
+
`Puid` is a simple, fast, flexible and efficient random ID generator:
397
411
398
-
-**Easy to use**
412
+
-**Ease**
399
413
400
-
Random ID generator is one line of code
414
+
Random ID generator specified in one line of code
401
415
402
416
-**Flexible**
403
417
404
418
Full control over entropy source, ID characters and amount of ID randomness
405
419
420
+
-**Explicit**
421
+
422
+
Clear specification of chosen level of randomness
423
+
406
424
-**Efficient**
407
425
408
-
Efficient use of system entropy
426
+
Maximum use of system entropy
409
427
410
428
-**Secure**
411
429
412
-
Easily specify a secure source of entropy
413
-
414
-
-**Clear intent**
430
+
Defaults to a secure source of entropy
431
+
432
+
-**Compact**
433
+
434
+
ID strings represent maximum entropy for characters used
415
435
416
-
Explicit declaration of chosen level of randomness
436
+
-**Secure**
437
+
438
+
Defaults to a secure source of entropy and at least 128 bits of ID entropy
Copy file name to clipboardExpand all lines: package.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
{
2
2
"name": "puid-js",
3
3
"version": "1.0.2",
4
-
"description": "Simple, fast, flexible and efficient generation of probably unique identifiers (`puid`, aka random strings) of intuitively specified entropy using pre-defined or custom characters.",
4
+
"description": "Simple, fast, flexible and efficient generation of probably unique identifiers (`puid`, aka random strings) of intuitively specified entropy using pre-defined or custom characters, including unicode",
0 commit comments