[swift-evolution] [Proposal] Random Unification

David Waite david at alkaline-solutions.com
Fri Nov 17 17:16:54 CST 2017

> On Nov 17, 2017, at 4:09 PM, Xiaodi Wu via swift-evolution <swift-evolution at swift.org> wrote:
> Certainly it's hard to defend Date.random (and yes, it might be useful for a fuzzer, but that's a very niche use case--and in that case the fuzzer should probably also generate invalid/non-existent dates, which surely Date.random should not do). But actually, Int.random followed by % is the much bigger issue and a very good cautionary tale for why T.random is not a good idea. Swift should help users do the correct thing, and getting a random value across the full domain and computing an integer modulus is never the correct thing to do because of modulo bias, yet it's a very common error to make. We are much better off eliminating this API and encouraging use of the correct API, thereby reducing the likelihood of users making this category of error.



More information about the swift-evolution mailing list