I'd be interested to know why the generic next
method in the extension is needed, perhaps someone familiar with the implementation can explain?
The generic next
seems to be doing exactly the same thing as:
UInt8.random(in: 0 ... UInt8.max, using: &rg)
UInt16.random(in: 0 ... UInt16.max, using: &rg)
UInt32.random(in: 0 ... UInt32.max, using: &rg)
UInt64.random(in: 0 ... UInt64.max, using: &rg)
no?
Why not simply remove the generic next
method in the extension and replace it with
UInt8.random(using: &rg)
UInt16.random(using: &rg)
...
Or, if it has to be a generic next
method in an extension to RandomNumberGenerator
, it could require that the type be given as an argument, which would solve the problem:
extension RandomNumberGenerator {
@inlinable
public mutating func next<T>(_ : T.Type) -> T
where T : FixedWidthInteger, T : UnsignedInteger
{
...
}
}
?
As a sidenote, this is what it looks like when I, as I normally do, let code completion help me with the exact type signatures of the required methods of a protocol:
As can be seen, the requirement is already satisfied by the (currently) self referential method shown first in the list of completions, so the one that I want:
public mutating func next() -> UInt64
is not in the list.