Skip to content

Commit 741c262

Browse files
committed
Refactor
Rename Random -> Entropy
1 parent 8d6539b commit 741c262

File tree

8 files changed

+76
-76
lines changed

8 files changed

+76
-76
lines changed

EntropyString.xcodeproj/project.pbxproj

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,25 @@
88

99
/* Begin PBXBuildFile section */
1010
E205C6AE1F1BFF66007C139E /* EntropyString.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E205C6A51F1BFF66007C139E /* EntropyString.framework */; };
11-
E205C6BC1F1BFFEC007C139E /* Random.swift in Sources */ = {isa = PBXBuildFile; fileRef = E287ADAD1F0E9DDC00DE6DF5 /* Random.swift */; };
11+
E205C6BC1F1BFFEC007C139E /* Entropy.swift in Sources */ = {isa = PBXBuildFile; fileRef = E287ADAD1F0E9DDC00DE6DF5 /* Entropy.swift */; };
1212
E205C6EB1F1C02E4007C139E /* EntropyString.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E205C6E21F1C02E3007C139E /* EntropyString.framework */; };
13-
E205C6F91F1C030E007C139E /* Random.swift in Sources */ = {isa = PBXBuildFile; fileRef = E287ADAD1F0E9DDC00DE6DF5 /* Random.swift */; };
13+
E205C6F91F1C030E007C139E /* Entropy.swift in Sources */ = {isa = PBXBuildFile; fileRef = E287ADAD1F0E9DDC00DE6DF5 /* Entropy.swift */; };
1414
E21779C81F3E7E260019CC42 /* Bytes.swift in Sources */ = {isa = PBXBuildFile; fileRef = E21779C71F3E7E260019CC42 /* Bytes.swift */; };
1515
E21779C91F3E7E260019CC42 /* Bytes.swift in Sources */ = {isa = PBXBuildFile; fileRef = E21779C71F3E7E260019CC42 /* Bytes.swift */; };
1616
E21779CA1F3E7E260019CC42 /* Bytes.swift in Sources */ = {isa = PBXBuildFile; fileRef = E21779C71F3E7E260019CC42 /* Bytes.swift */; };
1717
E21779CB1F3E7E260019CC42 /* Bytes.swift in Sources */ = {isa = PBXBuildFile; fileRef = E21779C71F3E7E260019CC42 /* Bytes.swift */; };
1818
E287AD9C1F0E9B9A00DE6DF5 /* EntropyString.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E287AD921F0E9B9A00DE6DF5 /* EntropyString.framework */; };
1919
E287ADA31F0E9B9A00DE6DF5 /* EntropyString.h in Headers */ = {isa = PBXBuildFile; fileRef = E287AD951F0E9B9A00DE6DF5 /* EntropyString.h */; settings = {ATTRIBUTES = (Public, ); }; };
20-
E287ADAE1F0E9DDC00DE6DF5 /* Random.swift in Sources */ = {isa = PBXBuildFile; fileRef = E287ADAD1F0E9DDC00DE6DF5 /* Random.swift */; };
20+
E287ADAE1F0E9DDC00DE6DF5 /* Entropy.swift in Sources */ = {isa = PBXBuildFile; fileRef = E287ADAD1F0E9DDC00DE6DF5 /* Entropy.swift */; };
2121
E287ADB51F0E9DEE00DE6DF5 /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = E287ADB21F0E9DEE00DE6DF5 /* Info.plist */; };
2222
E2B8C8171F3E2B8500171502 /* CharSet.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2B8C8161F3E2B8500171502 /* CharSet.swift */; };
23-
E2D2DD471F436AB3006846F7 /* Random.swift in Sources */ = {isa = PBXBuildFile; fileRef = E287ADAD1F0E9DDC00DE6DF5 /* Random.swift */; };
23+
E2D2DD471F436AB3006846F7 /* Entropy.swift in Sources */ = {isa = PBXBuildFile; fileRef = E287ADAD1F0E9DDC00DE6DF5 /* Entropy.swift */; };
2424
E2D2DD481F436AB6006846F7 /* CharSet.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2B8C8161F3E2B8500171502 /* CharSet.swift */; };
2525
E2D2DD491F436AB7006846F7 /* CharSet.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2B8C8161F3E2B8500171502 /* CharSet.swift */; };
2626
E2D2DD4A1F436AB8006846F7 /* CharSet.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2B8C8161F3E2B8500171502 /* CharSet.swift */; };
27-
E2E140531F422FB1003E02B0 /* RandomTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2E140521F422FB1003E02B0 /* RandomTests.swift */; };
28-
E2E140541F422FB1003E02B0 /* RandomTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2E140521F422FB1003E02B0 /* RandomTests.swift */; };
29-
E2E140551F422FB1003E02B0 /* RandomTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2E140521F422FB1003E02B0 /* RandomTests.swift */; };
27+
E2E140531F422FB1003E02B0 /* EntropyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2E140521F422FB1003E02B0 /* EntropyTests.swift */; };
28+
E2E140541F422FB1003E02B0 /* EntropyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2E140521F422FB1003E02B0 /* EntropyTests.swift */; };
29+
E2E140551F422FB1003E02B0 /* EntropyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2E140521F422FB1003E02B0 /* EntropyTests.swift */; };
3030
E2E140571F433A6D003E02B0 /* CharSetTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2E140561F433A6D003E02B0 /* CharSetTests.swift */; };
3131
E2E140581F433A6D003E02B0 /* CharSetTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2E140561F433A6D003E02B0 /* CharSetTests.swift */; };
3232
E2E140591F433A6D003E02B0 /* CharSetTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2E140561F433A6D003E02B0 /* CharSetTests.swift */; };
@@ -70,12 +70,12 @@
7070
E287AD951F0E9B9A00DE6DF5 /* EntropyString.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = EntropyString.h; sourceTree = "<group>"; };
7171
E287AD961F0E9B9A00DE6DF5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
7272
E287AD9B1F0E9B9A00DE6DF5 /* EntropyString-iOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "EntropyString-iOSTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
73-
E287ADAD1F0E9DDC00DE6DF5 /* Random.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Random.swift; sourceTree = "<group>"; };
73+
E287ADAD1F0E9DDC00DE6DF5 /* Entropy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Entropy.swift; sourceTree = "<group>"; };
7474
E287ADB21F0E9DEE00DE6DF5 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
7575
E287ADBA1F0EE3B600DE6DF5 /* EntropyString.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = EntropyString.playground; sourceTree = "<group>"; };
7676
E2B8C8161F3E2B8500171502 /* CharSet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CharSet.swift; sourceTree = "<group>"; };
7777
E2DDF28D1F68EDD700CE76CB /* Presentation.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; name = Presentation.playground; path = ../Presentation/Swift/Presentation.playground; sourceTree = "<group>"; };
78-
E2E140521F422FB1003E02B0 /* RandomTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RandomTests.swift; sourceTree = "<group>"; };
78+
E2E140521F422FB1003E02B0 /* EntropyTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EntropyTests.swift; sourceTree = "<group>"; };
7979
E2E140561F433A6D003E02B0 /* CharSetTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CharSetTests.swift; sourceTree = "<group>"; };
8080
/* End PBXFileReference section */
8181

@@ -174,7 +174,7 @@
174174
isa = PBXGroup;
175175
children = (
176176
E2B8C8161F3E2B8500171502 /* CharSet.swift */,
177-
E287ADAD1F0E9DDC00DE6DF5 /* Random.swift */,
177+
E287ADAD1F0E9DDC00DE6DF5 /* Entropy.swift */,
178178
E21779C71F3E7E260019CC42 /* Bytes.swift */,
179179
);
180180
path = Sources;
@@ -192,7 +192,7 @@
192192
isa = PBXGroup;
193193
children = (
194194
E2E140561F433A6D003E02B0 /* CharSetTests.swift */,
195-
E2E140521F422FB1003E02B0 /* RandomTests.swift */,
195+
E2E140521F422FB1003E02B0 /* EntropyTests.swift */,
196196
E287ADB21F0E9DEE00DE6DF5 /* Info.plist */,
197197
);
198198
path = EntropyStringTests;
@@ -486,7 +486,7 @@
486486
isa = PBXSourcesBuildPhase;
487487
buildActionMask = 2147483647;
488488
files = (
489-
E205C6BC1F1BFFEC007C139E /* Random.swift in Sources */,
489+
E205C6BC1F1BFFEC007C139E /* Entropy.swift in Sources */,
490490
E2D2DD481F436AB6006846F7 /* CharSet.swift in Sources */,
491491
E21779C91F3E7E260019CC42 /* Bytes.swift in Sources */,
492492
);
@@ -496,7 +496,7 @@
496496
isa = PBXSourcesBuildPhase;
497497
buildActionMask = 2147483647;
498498
files = (
499-
E2E140541F422FB1003E02B0 /* RandomTests.swift in Sources */,
499+
E2E140541F422FB1003E02B0 /* EntropyTests.swift in Sources */,
500500
E2E140581F433A6D003E02B0 /* CharSetTests.swift in Sources */,
501501
);
502502
runOnlyForDeploymentPostprocessing = 0;
@@ -505,7 +505,7 @@
505505
isa = PBXSourcesBuildPhase;
506506
buildActionMask = 2147483647;
507507
files = (
508-
E205C6F91F1C030E007C139E /* Random.swift in Sources */,
508+
E205C6F91F1C030E007C139E /* Entropy.swift in Sources */,
509509
E2D2DD491F436AB7006846F7 /* CharSet.swift in Sources */,
510510
E21779CA1F3E7E260019CC42 /* Bytes.swift in Sources */,
511511
);
@@ -515,7 +515,7 @@
515515
isa = PBXSourcesBuildPhase;
516516
buildActionMask = 2147483647;
517517
files = (
518-
E2E140551F422FB1003E02B0 /* RandomTests.swift in Sources */,
518+
E2E140551F422FB1003E02B0 /* EntropyTests.swift in Sources */,
519519
E2E140591F433A6D003E02B0 /* CharSetTests.swift in Sources */,
520520
);
521521
runOnlyForDeploymentPostprocessing = 0;
@@ -526,7 +526,7 @@
526526
files = (
527527
E21779CB1F3E7E260019CC42 /* Bytes.swift in Sources */,
528528
E2D2DD4A1F436AB8006846F7 /* CharSet.swift in Sources */,
529-
E2D2DD471F436AB3006846F7 /* Random.swift in Sources */,
529+
E2D2DD471F436AB3006846F7 /* Entropy.swift in Sources */,
530530
);
531531
runOnlyForDeploymentPostprocessing = 0;
532532
};
@@ -535,7 +535,7 @@
535535
buildActionMask = 2147483647;
536536
files = (
537537
E2B8C8171F3E2B8500171502 /* CharSet.swift in Sources */,
538-
E287ADAE1F0E9DDC00DE6DF5 /* Random.swift in Sources */,
538+
E287ADAE1F0E9DDC00DE6DF5 /* Entropy.swift in Sources */,
539539
E21779C81F3E7E260019CC42 /* Bytes.swift in Sources */,
540540
);
541541
runOnlyForDeploymentPostprocessing = 0;
@@ -544,7 +544,7 @@
544544
isa = PBXSourcesBuildPhase;
545545
buildActionMask = 2147483647;
546546
files = (
547-
E2E140531F422FB1003E02B0 /* RandomTests.swift in Sources */,
547+
E2E140531F422FB1003E02B0 /* EntropyTests.swift in Sources */,
548548
E2E140571F433A6D003E02B0 /* CharSetTests.swift in Sources */,
549549
);
550550
runOnlyForDeploymentPostprocessing = 0;

EntropyString/EntropyString.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// EntropyString
44
//
55
// Created by Paul Rogers on 7/16/17.
6-
// Copyright © 2017 Knoxen. All rights reserved.
6+
// Copyright © 2017-2018 Knoxen. All rights reserved.
77
//
88
@import Foundation;
99

EntropyString/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<key>CFBundleVersion</key>
2020
<string>$(CURRENT_PROJECT_VERSION)</string>
2121
<key>NSHumanReadableCopyright</key>
22-
<string>Copyright © 2017 Knoxen. All rights reserved.</string>
22+
<string>Copyright © 2017-2018 Knoxen. All rights reserved.</string>
2323
<key>NSPrincipalClass</key>
2424
<string></string>
2525
</dict>

Sources/Bytes.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Bytes.swift
33
// EntropyString
44
//
5-
// Copyright © 2017 Knoxen. All rights reserved.
5+
// Copyright © 2017-2018 Knoxen. All rights reserved.
66
//
77
// The MIT License (MIT)
88
//

Sources/CharSet.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// CharSet.swift
33
// EntropyString-iOS
44
//
5-
// Copyright © 2017 Knoxen. All rights reserved.
5+
// Copyright © 2017-2018 Knoxen. All rights reserved.
66
//
77
// The MIT License (MIT)
88
//
@@ -79,9 +79,9 @@ public struct CharSet {
7979

8080
self.chars = chars
8181
bitsPerChar = UInt8(log2(Float(length)))
82-
charsPerChunk = CharSet.lcm(bitsPerChar, Random.bitsPerByte) / bitsPerChar
82+
charsPerChunk = CharSet.lcm(bitsPerChar, Entropy.bitsPerByte) / bitsPerChar
8383

84-
if CharSet.lcm(bitsPerChar, Random.bitsPerByte) == Random.bitsPerByte {
84+
if CharSet.lcm(bitsPerChar, Entropy.bitsPerByte) == Entropy.bitsPerByte {
8585
ndxFn = CharSet.ndxFnForDivisor(bitsPerChar)
8686
}
8787
else {
@@ -93,7 +93,7 @@ public struct CharSet {
9393
///
9494
public func bytesNeeded(bits: Float) -> Int {
9595
let count = ceil(bits / Float(bitsPerChar))
96-
return Int(ceil(count * Float(bitsPerChar) / Float(Random.bitsPerByte)))
96+
return Int(ceil(count * Float(bitsPerChar) / Float(Entropy.bitsPerByte)))
9797
}
9898

9999
/// Determines index into `CharSet` characters when base is a multiple of 8.
@@ -111,7 +111,7 @@ public struct CharSet {
111111
private static func ndxFnForDivisor(_ bitsPerChar: UInt8) -> NdxFn {
112112
func ndxFn(bytes: [UInt8], chunk: Int, slice: UInt8) -> Ndx {
113113
let lShift = UInt8(bitsPerChar)
114-
let rShift = Random.bitsPerByte - bitsPerChar
114+
let rShift = Entropy.bitsPerByte - bitsPerChar
115115
return (bytes[chunk]<<UInt8(slice*lShift))>>rShift
116116
}
117117
return ndxFn
@@ -131,7 +131,7 @@ public struct CharSet {
131131
/// - return: The a function to index into the `CharSet` characters.
132132
private static func ndxFnForNonDivisor(_ bitsPerChar: UInt8) -> NdxFn {
133133
func ndxFn(bytes: [UInt8], chunk: Int, slice: UInt8) -> Ndx {
134-
let bitsPerByte = Random.bitsPerByte
134+
let bitsPerByte = Entropy.bitsPerByte
135135
let slicesPerChunk = lcm(bitsPerChar, bitsPerByte) / bitsPerByte
136136
let bNum = chunk * Int(slicesPerChunk)
137137

Sources/Random.swift renamed to Sources/Entropy.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//
2-
// Random.swift
2+
// Entropy.swift
33
// EntropyString
44
//
5-
// Copyright © 2017 Knoxen. All rights reserved.
5+
// Copyright © 2017-2018 Knoxen. All rights reserved.
66
//
77
// The MIT License (MIT)
88
//
@@ -26,35 +26,35 @@
2626
//
2727
import Foundation
2828

29-
/// Errors thrown by Random
29+
/// Errors thrown by Entropy
3030
public enum EntropyStringError: Error {
3131
case tooFewBytes
3232
case negativeEntropy
3333
case invalidCharCount
3434
case charsNotUnique
3535
}
3636

37-
public class Random {
37+
public class Entropy {
3838
static let bitsPerByte: UInt8 = 8
3939

4040
public private(set) var charSet: CharSet
4141

4242
// MARK: - Public Initializers
4343
//
44-
/// Create a `Random` instance
44+
/// Create a `Entropy` instance
4545
///
4646
/// - parameter charSet: The default `CharSet`
4747
public init(_ charSet: CharSet) {
4848
self.charSet = charSet
4949
}
5050

51-
/// Create a `Random` instance with default `CharSet` set to `.charSet32`
51+
/// Create a `Entropy` instance with default `CharSet` set to `.charSet32`
5252
///
5353
convenience public init() {
5454
self.init(CharSet.charSet32)
5555
}
5656

57-
/// Create a `Random` instance
57+
/// Create a `Entropy` instance
5858
///
5959
/// - paramter chars: String of characters for the `CharSet`
6060
///

Tests/EntropyStringTests/CharSetTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// EntropyString
44
//
55
// Created by Paul Rogers on 8/15/17.
6-
// Copyright © 2017 Knoxen. All rights reserved.
6+
// Copyright © 2017-2018 Knoxen. All rights reserved.
77
//
88

99
import XCTest
@@ -91,7 +91,7 @@ class CharSetTests: XCTestCase {
9191
func testBytesNeeded() {
9292
let doTest: (CharSet, Float) -> () = { (charSet: CharSet, bits: Float) -> () in
9393
let bytesNeeded = charSet.bytesNeeded(bits: bits)
94-
let atLeast = Int(ceil(bits / Float(Random.bitsPerByte)))
94+
let atLeast = Int(ceil(bits / Float(Entropy.bitsPerByte)))
9595
XCTAssertTrue(atLeast <= bytesNeeded)
9696
let atMost = atLeast + 1
9797
XCTAssertTrue(bytesNeeded <= atMost)

0 commit comments

Comments
 (0)