<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">I still would propose the random generator be designed as a random binary stream, with the user functionality being exposed on particular types (Int, Float, Array, etc) and not on that generator interface. For this I just picked a "read" method off of InputStream.<div class=""><br class=""></div><div class="">One nice thing about a simple, swappable random source is the ability to switch out a deterministic and/or repeatable source of randomness for the system while under test.</div><div class=""><br class=""></div><div class="">Also since the random data may be coming from system entropy and not from an algorithm, I'd recommend calling it RandomSource.</div><div class=""><br class=""></div><div class=""><div class=""><font color="#24292e" face="-apple-system, BlinkMacSystemFont, Segoe UI, Helvetica, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol" class=""><span style="font-size: 14px;" class="">protocol&nbsp;RandomSource&nbsp;{<br class="">&nbsp;&nbsp;//&nbsp;Reads up to a given number of bytes into a given buffer.<br class="">&nbsp;&nbsp;func&nbsp;read(_ buffer: UnsafeMutablePointer&lt;UInt8&gt;,&nbsp;maxLength:&nbsp;Int)<br class="">}</span></font></div><div class=""><br class=""></div><div class=""><span style="font-size: 14px; color: rgb(36, 41, 46); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';" class="">-DW</span></div><div class=""><font color="#24292e" face="-apple-system, BlinkMacSystemFont, Segoe UI, Helvetica, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol" class=""><span style="font-size: 14px;" class=""><br class=""></span></font><div><blockquote type="cite" class=""><div class="">On Nov 5, 2017, at 5:33 PM, Alejandro Alonso via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class="">

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" class="">
<title class=""></title>

<div class="">
<div name="messageBodySection" style="font-size: 14px; font-family: -apple-system, BlinkMacSystemFont, sans-serif;" class="">
<a href="https://github.com/apple/swift-evolution/pull/760" class="">https://github.com/apple/swift-evolution/pull/760</a>&nbsp;is the current API and proposed solution.</div>
<div name="messageSignatureSection" style="font-size: 14px; font-family: -apple-system, BlinkMacSystemFont, sans-serif;" class="">
<br class="">
- Alejandro</div>
<div name="messageReplySection" style="font-size: 14px; font-family: -apple-system, BlinkMacSystemFont, sans-serif;" class="">
<br class="">
On Nov 5, 2017, 6:18 PM -0600, Xiaodi Wu &lt;<a href="mailto:xiaodi.wu@gmail.com" class="">xiaodi.wu@gmail.com</a>&gt;, wrote:<br class="">
<blockquote type="cite" style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #1abc9c;" class="">
<div dir="ltr" class="">
<div class="">My comments are directed to the "more up-to-date" document that you just linked to in your reply to Jon. Is that one outdated? If so, can you send a link to the updated proposal and implementation for which you're soliciting feedback?</div>
<br class="">
<div class="gmail_extra"><br class="">
<div class="gmail_quote">On Sun, Nov 5, 2017 at 6:12 PM, Alejandro Alonso <span dir="ltr" class="">
&lt;<a href="mailto:aalonso128@outlook.com" target="_blank" class="">aalonso128@outlook.com</a>&gt;</span> wrote:<br class="">
<blockquote class="gmail_quote" style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #e67e22;">
<div class="">
<div name="messageBodySection" style="font-size:14px;font-family:-apple-system,BlinkMacSystemFont,sans-serif" class="">
The proposal and implementation have the current updated API. The link I sent Jon was the one I brought up a few weeks ago which is outdated now. The proposal answers all of your questions. As for `.random` being a function, some would argue that it behaves
 in the same way as `.first` and `.last` which are properties.</div>
<div class="HOEnZb"><font color="#888888" class=""></font>
<div name="messageSignatureSection" style="font-size:14px;font-family:-apple-system,BlinkMacSystemFont,sans-serif" class="">
<font color="#888888" class=""><br class="">
- Alejandro</font></div>
</div>
<div class="">
<div class="h5">
<div name="messageReplySection" style="font-size:14px;font-family:-apple-system,BlinkMacSystemFont,sans-serif" class="">
<br class="">
On Nov 5, 2017, 6:07 PM -0600, Xiaodi Wu &lt;<a href="mailto:xiaodi.wu@gmail.com" target="_blank" class="">xiaodi.wu@gmail.com</a>&gt;, wrote:<br class="">
<blockquote type="cite" style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #3498db;" class="">
<div dir="ltr" class="">A few quick thoughts:
<div class=""><br class="">
</div>
<div class="">I know that there's been some discussion that `(1...10).random` is the best spelling, but I'd like to push back on that suggestion. When I want a random number, I tend to think of the type I want first ("I want a random integer") and then a range ("I want
 a random integer between a and b"), not the other way around. My intuition is that `Int.random(in:)` will be more discoverable, both on that basis and because it is more similar to other languages' syntax (`Math.random` in JavaScript and `randint` in NumPy,
 for example). It also has the advantage that the type is explicit, which I think is particularly useful in this case because the value itself is, well, random.</div>
<div class=""><br class="">
</div>
<div class="">I would also argue that, `random` is most appropriately a method and not a property; there's no hard and fast rule for this, but the fact that the result is stochastic suggests (to me) that it's not a "property" of the range (or, for that matter, of the
 type).</div>
<div class=""><br class="">
</div>
<div class="">
<div class="">I would reiterate here my qualms about `Source` being the term used for a generator. These types are not a _source_ of entropy but rather a _consumer_ of entropy.</div>
</div>
<div class=""><br class="">
</div>
<div class="">`UnsafeRandomSource` needs to be renamed; "unsafe" has a specific meaning in Swift--that is, memory safety, and this is not it. Moreover, it's questionable whether this protocol is useful in any sense. What useful generic algorithms can one write with
 such a protocol?</div>
<div class=""><br class="">
</div>
<div class="">`XoroshiroRandom` cannot be seeded by any `Numeric` value; depending on the specific algorithm it needs a seed of a specific bit width. If you default the shared instance to being seeded with an `Int` then you will have to have distinct implementations
 for 32-bit and 64-bit platforms. This is unadvisable. On that note, your `UnsafeRandomSource` needs to have an associated type and not a generic `&lt;T : Numeric&gt;` for the seed.<br class="">
</div>
<div class=""><br class="">
</div>
<div class="">The default random number generator should be cryptographically secure; however, it's not clear to me that it should be device random.</div>
<div class=""><br class="">
</div>
<div class="">I agree with others that alternative random number generators other than the default RNG (and, if not default, possibly also the device RNG) should be accommodated by the protocol hierarchy but not necessarily supplied in the stdlib.</div>
<div class=""><br class="">
</div>
<div class="">The term `Randomizable` means something specific which is not how it's used in your proposed protocol.&nbsp;</div>
<div class=""><br class="">
</div>
<div class="">There's still the open question, not answered, about how requesting an instance of the hardware RNG behaves when there's insufficient or no entropy. Does it return nil, throw, trap, or wait? The proposed API does not clarify this point, although based
 on the method signature it cannot return nil or throw. Trapping might be acceptable but I'd be interested to hear your take as to why it is preferable.</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class="gmail_extra">
<div class="gmail_quote">On Sun, Nov 5, 2017 at 4:43 PM, Alejandro Alonso via swift-evolution
<span dir="ltr" class="">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;</span> wrote:<br class="">
<blockquote class="gmail_quote" style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #d35400;">
<div class="">
<div name="messageBodySection" style="font-size:14px;font-family:-apple-system,BlinkMacSystemFont,sans-serif" class="">
For the proof of concept, I had accidentally deleted that one. I have a more up to date one which was discussed a few weeks later.&nbsp;<a href="https://gist.github.com/Azoy/15f0518df38df9b722d4cb17bafea4c1" target="_blank" class="">https://gist.github.com<wbr class="">/Azoy/15f0518df38df9b722d4cb17<wbr class="">bafea4c1</a></div>
<div name="messageSignatureSection" style="font-size:14px;font-family:-apple-system,BlinkMacSystemFont,sans-serif" class="">
<br class="">
- Alejandro</div>
<div class="">
<div class="m_1947579187318224822gmail-h5">
<div name="messageReplySection" style="font-size:14px;font-family:-apple-system,BlinkMacSystemFont,sans-serif" class="">
<br class="">
On Nov 5, 2017, 4:37 PM -0600, Jonathan Hull &lt;<a href="mailto:jhull@gbis.com" target="_blank" class="">jhull@gbis.com</a>&gt;, wrote:<br class="">
<blockquote type="cite" style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #34495e;" class="">
Is there a link to the writeup?&nbsp; The one in the quote 404s.
<div class=""><br class="">
</div>
<div class="">Thanks,</div>
<div class="">Jon</div>
<div class=""><br class="">
<div class="">
<blockquote type="cite" style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #2ecc71;" class="">
<div class="">On Nov 5, 2017, at 2:10 PM, Alejandro Alonso via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:</div>
<br class="m_1947579187318224822gmail-m_3739135728595962658Apple-interchange-newline">
<div class="">
<div class="">
<div name="messageBodySection" style="font-size:14px;font-family:-apple-system,BlinkMacSystemFont,sans-serif" class="">
Hello once again Swift evolution community. I have taken the time to write up the proposal for this thread, and have provided an implementation for it as well. I hope to once again get good feedback on the overall proposal.</div>
<div name="messageSignatureSection" style="font-size:14px;font-family:-apple-system,BlinkMacSystemFont,sans-serif" class="">
<br class="">
- Alejandro</div>
<div name="messageReplySection" style="font-size:14px;font-family:-apple-system,BlinkMacSystemFont,sans-serif" class="">
<br class="">
On Sep 8, 2017, 11:52 AM -0500, Alejandro Alonso via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;, wrote:<br class="">
<blockquote type="cite" style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #9b59b6;" class="">
<div name="messageBodySection" style="font-size:14px;font-family:-apple-system,BlinkMacSystemFont,sans-serif" class="">
Hello swift evolution, I would like to propose a unified approach to `random()` in Swift. I have a simple implementation here&nbsp;<a href="https://gist.github.com/Azoy/5d294148c8b97d20b96ee64f434bb4f5" target="_blank" class="">https://gist.github.com/A<wbr class="">zoy/5d294148c8b97d20b96ee64f43<wbr class="">4bb4f5</a>.
 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.
<div class=""><br class="">
</div>
<div class="">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.</div>
<div class=""><br class="">
</div>
<div class="">I’d like to hear about your ideas on this proposal, or any implementation changes if need be.</div>
<div class=""><br class="">
</div>
<div class="">- Alejando</div>
</div>
<div name="messageReplySection" style="font-size:14px;font-family:-apple-system,BlinkMacSystemFont,sans-serif" class="">
<br class="">
<div class=""></div>
</div>
</blockquote>
</div>
</div>
______________________________<wbr class="">_________________<br class="">
swift-evolution mailing list<br class="">
<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" class="">https://lists.swift.org/mailma<wbr class="">n/listinfo/swift-evolution</a><br class="">
</div>
</blockquote>
</div>
<br class="">
</div>
</blockquote>
</div>
</div>
</div>
</div>
<br class="">
______________________________<wbr class="">_________________<br class="">
swift-evolution mailing list<br class="">
<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailma<wbr class="">n/listinfo/swift-evolution</a><br class="">
<br class="">
</blockquote>
</div>
<br class="">
</div>
</div>
</blockquote>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<br class="">
</div>
</div>
</blockquote>
</div>
</div>

_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></div></body></html>