<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On Oct 5, 2017, at 10:58 AM, Nate Cook 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=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">The edge case is really the same (empty ranges), it’s about what we do with the edge case. If we include the methods on integer types, usage will look like this:<div class=""><br class=""></div><div class=""><div class=""><font face="SFMono-Regular" class=""> let x = Int.random(in: 0..<5) // 3<br class=""> let y = Int.random(in: 0..<0) // runtime error</font></div><div class=""><br class=""></div><div class="">If we only have the collection methods, usage will look like this:</div><div class=""><br class=""></div><div class=""><div class=""><font face="SFMono-Regular" class=""> let x = (0..<5).random()! // 3<br class=""> let y = (0..<0).random()! // runtime error</font></div></div></div></div></div></blockquote><br class=""></div><div>These aren’t the forms I was suggesting, what I meant was:</div><div><br class=""></div><div>extension Int {<br class=""> init(randomInRange: Countable{Closed}Range<Int>)<br class="">}</div><div><br class=""></div><div>which gives:</div><div><span class="Apple-tab-span" style="white-space: pre;">        </span>let x = Int(randomInRange: 0..<5)</div><div><br class=""></div><div>The point of this is that you’re producing an Int (or whatever type). Regardless of whether the initializer is failable or not, this is the preferred way of creating a new value with some property: it is an initializer with a label.</div><div><br class=""></div><div>-Chris</div><div><br class=""></div><br class=""></body></html>