[swift-users] Make getting a random number more intuitive

Lukas Stabe ahti333 at gmail.com
Thu Jan 21 14:07:22 CST 2016


In addition to not being very obvious, arc4random is also not supported on platforms other than OSX.

For a uni project I did recently, I wrote FastRNG[1], which provides a protocol for random number generators, some convenience functions, and a few cross-platform generators.

Be aware that the generators are not able to produce cryptographically secure random, and I’m pretty new to this field. I basically just ported some generators from http://xorshift.di.unimi.it/ to Swift.

I think something like this (the protocol mostly) might be a good fit for future versions of the standard library, but I don’t think it meets the goals stated for Swift 3.

For now, feel free to use FastRNG. I’d also be happy to merge PRs (I think a generator based on arc4random and /dev/random would be pretty cool to have).

— Lukas


[1]:  https://github.com/Ahti/FastRNG
> On 21 Jan 2016, at 19:19, David Keck via swift-users <swift-users at swift.org> wrote:
> 
> Is there a plan to make it easier to obtain a random number? Our the current method involving arc4random_uniform isn't very obvious IMO.
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users



More information about the swift-users mailing list