From 0bcd36dda74b595ebe8b4c5b40a0c82b75ef6a0b Mon Sep 17 00:00:00 2001 From: Sami Samhuri Date: Mon, 21 Dec 2015 20:28:18 -0800 Subject: [PATCH] move randomInt to Utils --- Sources/CollectionType.swift | 16 ---------------- Sources/Utils.swift | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 16 deletions(-) create mode 100644 Sources/Utils.swift diff --git a/Sources/CollectionType.swift b/Sources/CollectionType.swift index 87c0fbf..083f837 100644 --- a/Sources/CollectionType.swift +++ b/Sources/CollectionType.swift @@ -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 diff --git a/Sources/Utils.swift b/Sources/Utils.swift new file mode 100644 index 0000000..f85c963 --- /dev/null +++ b/Sources/Utils.swift @@ -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) +}