[swift-evolution] [Proposal] Random Unification

Jonathan Hull jhull at gbis.com
Fri Sep 8 17:39:53 CDT 2017


Here is some Swift 3 code that allows simple repeatable repeatable random sequences by conforming to a protocol:
https://gist.github.com/jonhull/3655672529f8cf5b2eb248583d2cafb9
 
I now use a slightly more complicated version of this which allows more complex types (like colors) to be added and constrained in more interesting ways than just from…to (e.g. Colors with a fixed lightness/brightness, but a range in hue). The base is pretty much the same.

I have found that user-facing code often needs the idea of repeatable/re-creatable randomness. I originally created it to create a sketchy version of lines that had random offsets added to points along the line. If the randomness wasn’t reproducible, then the sketchiness of the line would shift around randomly every time there was a change.

The code I have provided above is not useful for any sort of cryptography/security though.  There are different reasons for randomness. Maybe that is something we should consider?

Thanks,
Jon

> On Sep 8, 2017, at 9:52 AM, Alejandro Alonso via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Hello swift evolution, I would like to propose a unified approach to `random()` in Swift. I have a simple implementation here https://gist.github.com/Azoy/5d294148c8b97d20b96ee64f434bb4f5 <https://gist.github.com/Azoy/5d294148c8b97d20b96ee64f434bb4f5>. This implementation is a simple wrapper over existing random functions so existing code bases will not be affected. Also, this approach introduces a new random feature for Linux users that give them access to upper bounds, as well as a lower bound for both Glibc and Darwin users. This change would be implemented within Foundation.
> 
> I believe this simple change could have a very positive impact on new developers learning Swift and experienced developers being able to write single random declarations.
> 
> I’d like to hear about your ideas on this proposal, or any implementation changes if need be.
> 
> - Alejando
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170908/e1ade844/attachment.html>


More information about the swift-evolution mailing list