Thanks everyone for the discussion. The core team has reviewed the feedback from this thread and other input, and has come to the following conclusions:
The core team continues to believe that the Random.default
type should be renamed before SE-0202 is released in Swift 4.2. The type name conflicts with the naming guidelines, which recommend that types should read as nouns and that names include all the words needed to avoid ambiguity. Random
is not sufficiently descriptive of what this type is. Deviation from the naming guidelines is allowed under some circumstances, such as for terms of art, in order to improve things like discoverability and readability. However, these motivations don't apply in this case: improving the discoverability of this type is actively harmful — users should be guided towards more appropriate methods such as Int.random(in:)
or Bool.random()
.
In considering the naming, the core team felt that SystemRandomNumberGenerator
was the most descriptive type name. While DefaultRandomNumberGenerator
matches the precedent of DefaultIndices
, the term "system" accurately describes the nature of the type.
In discussing the naming of the .default
property, the team came to the conclusion that this property is not sufficiently justified, and that the difficulty in naming it is a symptom of that. It is a computed property, rather than an actual instance, that generates a fresh instance each time. As such, the property is essentially sugar for creating an instance and using it. Given the only recommended use of the system generator is to default the generator for other methods, this comes down to the difference between:
extension MyType {
func random() -> MyType {
return random(using: &SystemRandomNumberGenerator.default)
}
}
and
extension MyType {
func random() -> MyType {
var g = SystemRandomNumberGenerator()
return random(using: &g)
}
}
Since in addition to the property syntax being misleading, the need to explicitly specify a generator is rare, and therefore doesn't justify increased library surface area, the team resolved the best approach was to remove the computed property.
The team still feel there is one issue with this type: that it is in the global namespace. We feel there is a better long term solution: to create a System
namespace, into which can go the a RandomNumberGenerator
type, as well as other useful system information such as the OS name, current PID etc. The core team would welcome pitches for such a namespace, for the Swift 5 timeframe.