SE-0202: Random Unification

I agree there is a lot to cover here!

  1. So yes, it is a little vague in the proposal about having the ability to extend these functions on RandomNumberGenerator, however yes, it is intended to be able to extend these functions, my apologies.

  2. So many people wanted this, however many more agreed that the stdlib is not a statistics library (Brent makes a great comment about this here: [Proposal] Random Unification - #17 by Brent_Royal-Gordon). A big portion of these discussions were about how much of this API belongs in the stdlib, and from a lot of comments in that discussion was that the stdlib should provide a default and non other.

  3. I agree this is functionality that some will look for, but again this goes back to the discussion that the stdlib is not a statistical library. I actually experimented with a distribution design and to me it felt like a reach for the stdlib. I decided against it, but made sure that it was still possible for developers to experiment on their own about how to incorporate such functionality with this API (Extending the next(upperBound:) function on generators is what comes to mind).

  4. Your argument that

doesn't hold up with your solution either. How would this function know you want a value other than Int or Double?

The answer is that you still explicitly have to tell the compiler what type of number you want. There are a couple of ways to represent this:

let x: UInt8 = random(0 ..< 10)
let x = random(0 as UInt8 ..< 10)
let x = random(0 ..< 10) as UInt8

Either way you look at this, you'll still be forced to define the type information (Of course you don't need this for Int or Double).

1 Like