File tree 1 file changed +4
-4
lines changed
Shuffle/Shuffle.playground
1 file changed +4
-4
lines changed Original file line number Diff line number Diff line change 3
3
import Foundation
4
4
5
5
/* Returns a random integer between 0 and n-1. */
6
- public func random( n: Int ) -> Int {
6
+ public func random( _ n: Int ) -> Int {
7
7
return Int ( arc4random_uniform ( UInt32 ( n) ) )
8
8
}
9
9
@@ -12,7 +12,7 @@ public func random(n: Int) -> Int {
12
12
/* Fisher-Yates / Knuth shuffle */
13
13
extension Array {
14
14
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 ) {
16
16
let j = random ( i + 1 )
17
17
if i != j {
18
18
swap ( & self [ i] , & self [ j] )
@@ -29,8 +29,8 @@ list.shuffle()
29
29
30
30
31
31
/* 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 )
34
34
for i in 0 ..< n {
35
35
let j = random ( i + 1 )
36
36
if i != j {
You can’t perform that action at this time.
0 commit comments