mirror of
https://github.com/samsonjs/SwiftBatteries.git
synced 2026-03-25 09:25:51 +00:00
15 lines
305 B
Swift
15 lines
305 B
Swift
#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)
|
|
}
|