Skip to content

Commit 648e908

Browse files
committed
Add TLDR 2
1 parent 9eb367b commit 648e908

File tree

4 files changed

+54
-2
lines changed

4 files changed

+54
-2
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//: [Previous](@previous)
2+
//: ## TLDR 2
3+
//: ### Take Away
4+
//:
5+
//: - You don't need random strings of length L.
6+
//: - String length is a by-product, not a goal.
7+
//: - You need unique strings.
8+
//: - Uniqueness is too onerous. You'll do fine with probabilistically unique strings.
9+
//: - Probabilistic uniqueness involves measured risk.
10+
//: - Risk is measured as *"1 in __n__ chance of generating a repeat"*
11+
//: - Bits of entropy gives you that measure.
12+
//: - You need to a total of **_N_** strings with a risk **_1/n_** of repeat.
13+
//: - The characters are arbitrary.
14+
//: - You need `EntropyString`.
15+
import EntropyString
16+
17+
let N: Entropy.Power = .ten06
18+
let n: Entropy.Power = .ten09
19+
var bits = Entropy.bits(for: N, risk: n)
20+
let string = RandomString.entropy(of: bits, using: .charSet32)
21+
//: * callout(string): DdHrT2NdrHf8tM
22+

EntropyString.playground/contents.xcplayground

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2-
<playground version='6.0' target-platform='ios' display-mode='raw'>
2+
<playground version='6.0' target-platform='ios' display-mode='rendered'>
33
<pages>
44
<page name='Table of Contents'/>
55
<page name='TLDR'/>
@@ -11,5 +11,6 @@
1111
<page name='Efficiency'/>
1212
<page name='Secure Bytes'/>
1313
<page name='Custom Bytes'/>
14+
<page name='TLDR2'/>
1415
</pages>
1516
</playground>

EntropyString.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Pod::Spec.new do |s|
44
s.name = "EntropyString"
5-
s.version = "1.2.0"
5+
s.version = "1.2.3"
66
s.summary = "Efficiently generate cryptographically strong random strings of specified entropy from various character sets."
77

88
s.description = <<-DESC

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Efficiently generate cryptographically strong random strings of specified entrop
1515
- [Efficiency](#Efficiency)
1616
- [Secure Bytes](#SecureBytes)
1717
- [Custom Bytes](#CustomBytes)
18+
- [TL;DR 2](#TLDR2)
1819

1920
[TOC](#TOC)
2021

@@ -515,3 +516,31 @@ The __bytes__ provided can come from any source. However, the number of bytes mu
515516
Note how the number of bytes needed is dependent on the number of characters in our set. In using a string to represent entropy, we can only have multiples of the bits of entropy per character used. So in the example above, to get at least 32 bits of entropy using a character set of 32 characters (5 bits per char), we'll need enough bytes to cover 35 bits, not 32, so a `tooFewBytes` error is thrown.
516517

517518
[TOC](#TOC)
519+
520+
## <a name="TLDR2"></a>TL;DR 2
521+
522+
### Take Away
523+
524+
- You don't need random strings of length L.
525+
- String length is a by-product, not a goal.
526+
- You need unique strings.
527+
- Uniqueness is too onerous. You'll do fine with probabilistically unique strings.
528+
- Probabilistic uniqueness involves measured risk.
529+
- Risk is measured as *"1 in __n__ chance of generating a repeat"*
530+
- Bits of entropy gives you that measure.
531+
- You need to a total of **_N_** strings with a risk **_1/n_** of repeat.
532+
- The characters are arbitrary.
533+
- You need `EntropyString`.
534+
535+
```swift
536+
import EntropyString
537+
538+
let N: Entropy.Power = .ten06
539+
let n: Entropy.Power = .ten09
540+
var bits = Entropy.bits(for: N, risk: n)
541+
let string = RandomString.entropy(of: bits, using: .charSet32)
542+
```
543+
544+
> DdHrT2NdrHf8tM
545+
546+
[TOC](#TOC)

0 commit comments

Comments
 (0)