move randomInt to Utils

This commit is contained in:
Sami Samhuri 2015-12-21 20:28:18 -08:00
parent 3f0daeded7
commit 0bcd36dda7
2 changed files with 15 additions and 16 deletions

View file

@ -1,11 +1,5 @@
import Foundation
#if os(Linux)
import Glibc
#else
import Darwin
#endif
public extension CollectionType {
typealias T = Generator.Element
@ -32,16 +26,6 @@ public extension CollectionType {
}
/// Returns a random integer between 1 and max
func randomInt(max: Int) -> Int {
#if os(Linux)
let n = random() % max
#else
let n = arc4random_uniform(UInt32(max))
#endif
return 1 + Int(n)
}
public extension CollectionType where Index: RandomAccessIndexType {
/// Returns a random element, or nil if the collection is empty

15
Sources/Utils.swift Normal file
View file

@ -0,0 +1,15 @@
#if os(Linux)
import Glibc
#else
import Darwin
#endif
/// Returns a random integer between 1 and max, inclusive.
public func randomInt(max: Int) -> Int {
#if os(Linux)
let n = random() % max
#else
let n = arc4random_uniform(UInt32(max))
#endif
return 1 + Int(n)
}