SE-0202 Amendment: Naming of the standard library random number generator

I'm not suggesting the current name is 'actively harmful', but given the proposal isn't implemented yet in public Swift I think there is a much lower bar needed to critique it and change it to something better. DefaultRandomNumberGenerator.shared is better, and I believe we should roll with that.

I brought up the same opinion in the review phase and it seemed to gain some community acceptance; an administrative error has led to this amendment thread being necessary as explained at the bottom of the original post.

And just to agree with what others saying here, I too believe the best choice here would be to use a future ability to nest types and property definitions inside protocols. However, this proposed name change is forwards compatible. DefaultRandomNumberGenerator.shared would be the formal definition of the type, and RandomNumberGenerator.default would be a property on the protocol.

Similarly, a formal Random namespace (either via a case-less enum or language feature) would also still require the underlying default generator to be named something; i.e:

enum Random {
   static var defaultGenerator: DefaultRandomNumberGenerator { return ... }
}

In summary, Random.default is not a terrible name but I believe obvious alternatives exist that provide superior clarity and consistency with the standard library. And there is no source compatibility argument to be had here.

2 Likes