Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift arc4random_uniform(max) in Linux

I'm working with Swift in Ubuntu, and I am getting an error that arc4random is an unresolved identifier. More information on this known bug here. Basically, the function only exists in BSD distros. I've tried module mapping header files, apt-getting packages, and I get more and more errors, which is not worth pursuing since this one function is not used very often.

Are there any functions to get pseudo random numbers with an upper-bound parameter that is compatible with Swift in Linux?

like image 811
Tyress Avatar asked Dec 08 '16 08:12

Tyress


1 Answers

Swift 4.2

let random = Int.random(in: 0...100)

https://developer.apple.com/documentation/swift/int/2995648-random

PS. It works in Linux.

like image 119
Sergey Di Avatar answered Oct 05 '22 19:10

Sergey Di