Skip to content

Commit

Permalink
Updated random number generation to Swift 4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
iillx committed Nov 1, 2018
1 parent ace62f8 commit a1d65fc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
7 changes: 2 additions & 5 deletions Set Cover (Unweighted)/SetCover.playground/Contents.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
// SetCover

// last checked with Xcode 9.0b4
#if swift(>=4.0)
print("Hello, Swift 4!")
#endif

let universe1 = Set(1...7)
let array1 = randomArrayOfSets(covering: universe1)
let cover1 = universe1.cover(within: array1)
Expand Down Expand Up @@ -36,3 +31,5 @@ let emptySet = Set<Int>()
let coverTest1 = emptySet.cover(within: array1)
let coverTest2 = universe1.cover(within: Array<Set<Int>>())
let coverTest3 = emptySet.cover(within: Array<Set<Int>>())


Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ public func randomArrayOfSets<T>(covering universe: Set<T>,

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

while true {
let randomUniverseIndex = Int(arc4random_uniform(UInt32(universe.count)))
let randomUniverseIndex = Int.random(in: 0...universe.count)
for (setIndex, value) in universe.enumerated() {
if setIndex == randomUniverseIndex {
generatedSet.insert(value)
Expand Down

0 comments on commit a1d65fc

Please sign in to comment.