<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Nov 22, 2017, at 8:55 PM, Alejandro Alonso via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> 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="">
I pushed some updates to the proposal with a reflected API, but I do not agree that we should rid the API of T.random just because some users will misuse it. I think the correct solution here is to include T.random(in:) (which does not return an optional making
it not a second typing of (min ... max).random). Like Jonathon said, autocomplete will display both of these and users will be able to select random(in:). I also disagree that T.random is _always_ followed by modulo because if we look at arc4random() it’s
range is the whole domain of UInt32. Users don’t put a modulo here because they know the correct way to do it is through arc4random_uniform(), either through online tutorials, or by reading documentation.</div></div></div></blockquote><br class=""></div><div>What evidence do you have that "users…know the correct way to do it"?</div><div><br class=""></div><div>I searched for arc4random and arc4random_uniform in a large Apple codebase.</div><div>723 files used arc4random.</div><div>296 files used arc4random_uniform.</div><div><br class=""></div><div>By eyeball, at least 80% of the arc4random() uses were of the form</div><div> arc4random() % something</div><div>or </div><div> (some_float_type)arc4random() / something</div><div>which are non-uniform ways to get a random integer and floating-point values, respectively.</div><div><br class=""></div><div>Few calls to arc4random() were obviously initializing random bytes for purposes like crypto or networking, but much of Apple's crypto code would likely have used other API like arc4random_buf() or CCRandomCopyBytes() so that may not be a good estimate.</div><div><br class=""></div><div><br class=""></div><div>-- </div><div>Greg Parker <a href="mailto:gparker@apple.com" class="">gparker@apple.com</a> Runtime Wrangler</div><div><br class=""></div><div><br class=""></div></body></html>