Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Enables arc4random_uniform in Swift on Ubuntu, just add this to the top of your main.swift file under the rest of your imports.
#if os(Linux)
import SwiftGlibc
public func arc4random_uniform(_ max: UInt32) -> Int32 {
return (SwiftGlibc.rand() % Int32(max-1))

monokrome commented Feb 10, 2017

@rymcol Unlike arc4random, doesn't this have modulo bias problems?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment