Skip to content

Commit a1d65fc

Browse files
committed
Updated random number generation to Swift 4.2
1 parent ace62f8 commit a1d65fc

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

Set Cover (Unweighted)/SetCover.playground/Contents.swift

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
// SetCover
22

3-
// last checked with Xcode 9.0b4
4-
#if swift(>=4.0)
5-
print("Hello, Swift 4!")
6-
#endif
7-
83
let universe1 = Set(1...7)
94
let array1 = randomArrayOfSets(covering: universe1)
105
let cover1 = universe1.cover(within: array1)
@@ -36,3 +31,5 @@ let emptySet = Set<Int>()
3631
let coverTest1 = emptySet.cover(within: array1)
3732
let coverTest2 = universe1.cover(within: Array<Set<Int>>())
3833
let coverTest3 = emptySet.cover(within: Array<Set<Int>>())
34+
35+

Set Cover (Unweighted)/SetCover.playground/Sources/RandomArrayOfSets.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ public func randomArrayOfSets<T>(covering universe: Set<T>,
1414

1515
while true {
1616
var generatedSet = Set<T>()
17-
let targetSetSize = Int(arc4random_uniform(UInt32(maxSetSize)) + 1)
17+
let targetSetSize = Int.random(in: 0...maxSetSize) + 1
1818

1919
while true {
20-
let randomUniverseIndex = Int(arc4random_uniform(UInt32(universe.count)))
20+
let randomUniverseIndex = Int.random(in: 0...universe.count)
2121
for (setIndex, value) in universe.enumerated() {
2222
if setIndex == randomUniverseIndex {
2323
generatedSet.insert(value)

0 commit comments

Comments
 (0)