Skip to content

Commit d244ba5

Browse files
authored
fix for Swift 3
1 parent 5f8f384 commit d244ba5

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Shuffle/Shuffle.playground/Contents.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import Foundation
44

55
/* Returns a random integer between 0 and n-1. */
6-
public func random(n: Int) -> Int {
6+
public func random(_ n: Int) -> Int {
77
return Int(arc4random_uniform(UInt32(n)))
88
}
99

@@ -12,7 +12,7 @@ public func random(n: Int) -> Int {
1212
/* Fisher-Yates / Knuth shuffle */
1313
extension Array {
1414
public mutating func shuffle() {
15-
for i in (count - 1).stride(through: 1, by: -1) {
15+
for i in stride(from: count - 1, through: 1, by: -1) {
1616
let j = random(i + 1)
1717
if i != j {
1818
swap(&self[i], &self[j])
@@ -29,8 +29,8 @@ list.shuffle()
2929

3030

3131
/* Create a new array of numbers that is already shuffled. */
32-
public func shuffledArray(n: Int) -> [Int] {
33-
var a = [Int](count: n, repeatedValue: 0)
32+
public func shuffledArray(_ n: Int) -> [Int] {
33+
var a = [Int](repeating: 0, count: n)
3434
for i in 0..<n {
3535
let j = random(i + 1)
3636
if i != j {

0 commit comments

Comments
 (0)