Skip to content

Instantly share code, notes, and snippets.

@rymcol
Created September 22, 2016 22:15
Show Gist options
  • Save rymcol/48a505c2a1c874daea52a296a2687f5f to your computer and use it in GitHub Desktop.
Save rymcol/48a505c2a1c874daea52a296a2687f5f to your computer and use it in GitHub Desktop.
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))
}
#endif
@monokrome
Copy link

monokrome commented Feb 10, 2017

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

@Kaiwen20111998
Copy link

@rymcol thank you my friend for these lines. Blessings.

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