<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body><div>Hi All,<br></div>
<div>&nbsp;</div>
<div>Thanks a lot for the quality feedback. I think that not only answers my question, but has also swayed me in the direction of not having Random() in the standard library. &nbsp;At least for now. <br></div>
<div>&nbsp;</div>
<div>My original thinking was along the lines of what you suggest in that leaving it out might encourage people to build bad implementations. &nbsp;But you're point is valid, people will probably do that anyway if they feel so inclined.&nbsp;<br></div>
<div>&nbsp;</div>
<div>Whilst I still think it might be a good building block and having a solid PRNG in the stnd library may make sense down the road, it seems there are so many good reasons to leave this up to another library. &nbsp;Its clearly not as straight forward as my original thinking suggested.&nbsp;<br></div>
<div><br>Thanks very much for the detailed responses!&nbsp;</div>
<div>&nbsp;</div>
<div id="sig48843321"><div class="signature">--<br></div>
<div class="signature">&nbsp; James Andrews<br></div>
<div class="signature">&nbsp; james@enigmanorth.com<br></div>
<div class="signature">&nbsp;</div>
</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>On Mon, Jul 4, 2016, at 06:37 AM, Gwynne Raskind wrote:<br></div>
<blockquote type="cite"><div>C++11 defines PRNGs in the STL, but even then the API is fairly complex thanks to the need for so many different options for source, distribution, seeds, security... - and it *still* doesn’t cover all of what I consider the obvious cases (YMMV).<br></div>
<div>&nbsp;</div>
<div><div>I agree with Robert here, Swift isn’t ready to have that heavy a functionality be part of its core library. For that matter, I question if it’s even a question of readiness so much as one of the API being suitable to a stdlib at all! Having the basic tools available via Darwin/Glibc and/or Foundation is plenty. If you have a need for stronger guarantees in your entropy than you can get from the common functions like rand, random, *rand48, arc4random, etc., it’s unlikely that any stdlib-provided option is going to meet your needs anyway.<br></div>
<div><div>&nbsp;</div>
<div>I mean, not that I don’t wish there was something like ***SSL’s RAND functionality around, but that just underscores the heck out of how much this is something that belongs in its own library and is too heavy for the stdlib. A coherent, vaguely safe API for randomness is nontrivial, to say the least.<br></div>
<div>&nbsp;</div>
<div>In fact, the strongest argument against it is that it’s just too easy for novices to shoot themselves in the foot with a builtin PRNG. Swift is supposed to make it *harder* to write broken unsafe code, not easier. And that’s not even considering that of the available OS-level functions only random_r() explicitly provides a thread-safety guarantee (so it’s even *easier* for users to mess themselves up without even realizing it, especially with libdispatch being so awesome in Swift 3).<br></div>
<div>&nbsp;</div>
<div>Swift shouldn't promote the use of RNGs by users who don't understand their pitfalls, and adding it to the stdlib does just that. At least forcing users to explicitly call into C APIs, or find existing libraries which have hopefully already focused their time on these considerations, adds an extra step that will ideally lead them to be a bit more conservative - C is "hard mode" from Swift’s POV. (One could argue that it’ll instead encourage them to roll their own insecure implementations, but that’ll happen with or without a builtin API so why make it easier?)<br></div>
<div><div><div>&nbsp;</div>
<div><div>-- Gwynne Raskind<br></div>
<div>More magic than a mere signature can contain<br></div>
</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div><blockquote type="cite"><div>On Jul 3, 2016, at 13:27, Robert Widmann via swift-dev &lt;<a href="mailto:swift-dev@swift.org">swift-dev@swift.org</a>&gt; wrote:<br></div>
<div>&nbsp;</div>
<div><div style="font-family:Helvetica, Arial;font-size:13px;font-style:normal;font-weight:normal;letter-spacing:normal;orphans:auto;text-align:start;text-indent:0px;text-transform:none;white-space:normal;widows:auto;word-spacing:0px;-webkit-text-stroke-width:0px;">&nbsp;</div>
<div style="font-family:Helvetica, Arial;font-size:13px;font-style:normal;font-weight:normal;letter-spacing:normal;orphans:auto;text-align:start;text-indent:0px;text-transform:none;white-space:normal;widows:auto;word-spacing:0px;-webkit-text-stroke-width:0px;"><div>Trouble is, most modern languages disagree with that and have chosen to split them out of their standard libraries.<br></div>
<div>&nbsp;</div>
<div>- Rust&nbsp;<a href="https://github.com/rust-lang-nursery/rand">https://github.com/rust-lang-nursery/rand</a><br></div>
<div>- Go&nbsp;<a href="https://golang.org/pkg/math/rand/">https://golang.org/pkg/math/rand/</a><br></div>
<div>- Dart&nbsp;<a href="https://api.dartlang.org/stable/1.17.1/dart-math/Random-class.html">https://api.dartlang.org/stable/1.17.1/dart-math/Random-class.html</a><br></div>
<div>- Elm&nbsp;<a href="https://github.com/jcollard/elm-random">https://github.com/jcollard/elm-random</a><br></div>
<div>- Haskell&nbsp;<a href="http://hackage.haskell.org/package/random-1.1/docs/System-Random.html#">http://hackage.haskell.org/package/random-1.1/docs/System-Random.html#</a><br></div>
<div>&nbsp;</div>
<div><div>As far as I can see, recent languages that do have [P]RNGs in their standard libraries are the ones that rely on massive STLs: Clojure, Scala, (java.*), C#, F# (.NET), Python, Ruby, (built-ins. &nbsp;Perhaps by virtue of their implementations in C).<br></div>
<div>&nbsp;</div>
<div>Speaking as someone that has had to write such a control for a library, I don't think it should be included, at least not yet. &nbsp;Not because it's not useful, but because there doesn't seem to be a concrete plan for how it will work here to suit more than one use-case ("gimme a random number"). &nbsp;[P]RNGs are not one-size-fits-all and if the community upholds one particular implementation, it will uphold not just the good but the bad of the invariants it carries with it. &nbsp;Better to let the community offer a wide selection of algorithms and interfaces and let the user pick than let them reach for a tailor-made tool for a broad class of functionality.<br></div>
<div>&nbsp;</div>
<div>~Robert Widmann<br></div>
</div>
<div><div>&nbsp;</div>
<div>2016/07/03 5:37、James Andrews via swift-dev &lt;<a href="mailto:swift-dev@swift.org">swift-dev@swift.org</a>&gt; のメッセージ:<br></div>
</div>
<blockquote type="cite"><div><div style="font-family:Helvetica, Arial;font-size:13px;margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;">Thanks for the feedback. I agree in that I believe the standard library should be able to grow. I think a PRNG implementation is a sufficiently “atomic” building block to be included in the standard library for a modern language these days.&nbsp;<br></div>
<div style="font-family:Helvetica, Arial;font-size:13px;margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;">&nbsp;</div>
<div style="font-family:Helvetica, Arial;font-size:13px;margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;">As to the implementation, would it not be foolish to stray to far from the already well proven, &nbsp;existing well understood PRNG implementations?<br></div>
<div>&nbsp;</div>
<div><div><span class="font" style="font-family:helvetica, arial"><span class="size" style="font-size:13px"></span></span>Thanks,<br></div>
<div>James<br></div>
<div>&nbsp;</div>
</div>
<div>&nbsp;</div>
<p>On 3 July 2016 at 07:46:16, Austin Zheng (<a href="mailto:austinzheng@gmail.com">austinzheng@gmail.com</a>) wrote:<br></p><blockquote type="cite"><div>&nbsp;</div>
<div><div>&nbsp;</div>
<div><span>I am also just a random guy, and I agree with much of what Brent says, but my personal opinion is that the standard library should be allowed to grow in the future to encompass areas whose generality and usefulness are comparable to those of current standard library constructs. I would consider a sufficiently well-designed suite of PRNGs to fall into this category.<span>&nbsp;</span><br><br>I guess what I'm saying is that, after Swift 3.0 is released, someone (maybe you!) should develop an argument as to why PRNGs belong in the standard library, and pitch it to the swift-evolution list. The worst that can happen is that people (or the core team) disagrees on principle, and at least you have an answer. But if there's interest a proposal can be drafted and taken to the review stage, at which point it'll be considered and possibly accepted.<span>&nbsp;</span><br><br>Best,<span>&nbsp;</span><br>Austin<span>&nbsp;</span><br><br>&gt; On Jul 2, 2016, at 11:30 PM, Brent Royal-Gordon via swift-dev &lt;<a href="mailto:swift-dev@swift.org">swift-dev@swift.org</a>&gt; wrote:<span>&nbsp;</span><br>&gt;<span>&nbsp;</span><span>&nbsp;</span><br>&gt;&gt; On Jun 24, 2016, at 6:38 AM, James Andrews via swift-dev &lt;<a href="mailto:swift-dev@swift.org">swift-dev@swift.org</a>&gt; wrote:<span>&nbsp;</span><br>&gt;&gt;<span>&nbsp;</span><span>&nbsp;</span><br>&gt;&gt; Is there a reason why random() is missing from the standard library? Is<span>&nbsp;</span><br>&gt;&gt; it just a matter of someone implementing it?<span>&nbsp;</span><br>&gt;<span>&nbsp;</span><span>&nbsp;</span><br>&gt; (Note: I'm just a guy, not someone in a leadership position.)<span>&nbsp;</span><br>&gt;<span>&nbsp;</span><span>&nbsp;</span><br>&gt; Random number generation is surprisingly complicated:<span>&nbsp;</span><br>&gt;<span>&nbsp;</span><span>&nbsp;</span><br>&gt; * Is it a truly random number generator or a pseudorandom one?<span>&nbsp;</span><br>&gt; * If it's truly random:<span>&nbsp;</span><br>&gt; * Where are we getting the random data?<span>&nbsp;</span><br>&gt; * Does it require platform-specific code?<span>&nbsp;</span><br>&gt; * Is there I/O involved?<span>&nbsp;</span><br>&gt; * If it's pseudorandom:<span>&nbsp;</span><br>&gt; * What's our goal here―cryptography, statistics, both, neither? Cryptographic PRNGs are slow for statistics, but statistical PRNGs break the security of crypto algorithms.<span>&nbsp;</span><br>&gt; * What algorithm?<span>&nbsp;</span><br>&gt; * Does it use shared state, or do you initialize your own RNG instance?<span>&nbsp;</span><br>&gt; * If it's shared:<span>&nbsp;</span><br>&gt; * How does it behave under concurrency?<span>&nbsp;</span><br>&gt; * Can you change the seed?<span>&nbsp;</span><br>&gt; * If it's not shared:<span>&nbsp;</span><br>&gt; * Can you seed it?<span>&nbsp;</span><br>&gt; * How big is the seed?<span>&nbsp;</span><br>&gt; * Where does the default seed come from?<span>&nbsp;</span><br>&gt; * Can you save and restore the state?<span>&nbsp;</span><br>&gt;<span>&nbsp;</span><span>&nbsp;</span><br>&gt; The Swift standard library is deep in very narrow, fundamental areas: features requiring compiler support, control flow, basic types, fundamental string handling, and sequences and collections. There's just barely enough console I/O and argument support to write a very basic command-line program. There's no file I/O, no concurrency, no networking, not even environment variables. Those things come from Foundation or from other libraries.<span>&nbsp;</span><br>&gt;<span>&nbsp;</span><span>&nbsp;</span><br>&gt; Random-number generation is another one of those things that Swift leaves to libraries. It is complicated, platform-specific (but not generally architecture-specific), subject to app-specific requirements, implementable in userspace, and does not require compiler support. Ultimately, it simply *does not need to be part of the language* in the way the things in the standard library are. If we wanted to make a protocol for random number generators, we would pretty much just end up with Sequence or Collection, and we already have those sitting in the standard library. The rest is finicky details we can leave to platform creators, library implementors, and users while we work on the things only we can do, like improving our numeric protocols so we can support BigInts and BigFloats.<span>&nbsp;</span><br>&gt;<span>&nbsp;</span><span>&nbsp;</span><br>&gt; --<span>&nbsp;</span><span>&nbsp;</span><br>&gt; Brent Royal-Gordon<span>&nbsp;</span><br>&gt; Architechies<span>&nbsp;</span><br>&gt;<span>&nbsp;</span><span>&nbsp;</span><br>&gt; _______________________________________________<span>&nbsp;</span><br>&gt; swift-dev mailing list<span>&nbsp;</span><br>&gt;<span>&nbsp;</span><a href="mailto:swift-dev@swift.org">swift-dev@swift.org</a><span>&nbsp;</span><br>&gt;<span>&nbsp;</span><a href="https://lists.swift.org/mailman/listinfo/swift-dev">https://lists.swift.org/mailman/listinfo/swift-dev</a><span>&nbsp;</span><br></span></div>
</div>
<div>&nbsp;</div>
</blockquote></div>
</blockquote><blockquote type="cite"><div><div><span>_______________________________________________</span><br></div>
<div><span>swift-dev mailing list</span><br></div>
<div><span><a href="mailto:swift-dev@swift.org">swift-dev@swift.org</a></span><br></div>
<div><span><a href="https://lists.swift.org/mailman/listinfo/swift-dev">https://lists.swift.org/mailman/listinfo/swift-dev</a></span><br></div>
</div>
</blockquote></div>
<div><span class="font" style="font-family:Helvetica, Arial"><span class="size" style="font-size:13px">_______________________________________________</span></span><br></div>
<div><span class="font" style="font-family:Helvetica, Arial"><span class="size" style="font-size:13px">swift-dev mailing list</span></span><br></div>
<div><a style="font-family:Helvetica, Arial;font-size:13px;font-style:normal;font-weight:normal;letter-spacing:normal;orphans:auto;text-align:start;text-indent:0px;text-transform:none;white-space:normal;widows:auto;word-spacing:0px;-webkit-text-stroke-width:0px;" href="mailto:swift-dev@swift.org">swift-dev@swift.org</a><br></div>
<div><a style="font-family:Helvetica, Arial;font-size:13px;font-style:normal;font-weight:normal;letter-spacing:normal;orphans:auto;text-align:start;text-indent:0px;text-transform:none;white-space:normal;widows:auto;word-spacing:0px;-webkit-text-stroke-width:0px;" href="https://lists.swift.org/mailman/listinfo/swift-dev">https://lists.swift.org/mailman/listinfo/swift-dev</a><br></div>
</div>
</blockquote></div>
</div>
</div>
</div>
</div>
</blockquote><div>&nbsp;</div>
</body>
</html>