[swift-evolution] Random

Jonathan Hull jhull at gbis.com
Fri Mar 3 23:55:37 CST 2017


This is a small improvement, but I still think it is worthwhile.

I would like to see an 'init(randomIn: Range<Self>)’ added to Numeric (where Comparable), which would return a random number in the given range.  It is something I have added myself to a subset of number types, but it really should be part of the standard library since there are a million small number types that have to be added individually, there are a couple of tricky edge cases to get right, and my version won’t work with Numeric types added by others.

I would also like to see a ‘randomElement’ method added to collection.  This is much easier to get right ourselves, but it comes up often enough in generic code that I still think it is a worthwhile addition…

Thanks,
Jon


More information about the swift-evolution mailing list