An API for bulk random bytes

I definitely see the need for this so big +1 from my side. However, only adding an unsafe version seems to be at odds with Swifts safety first principal. I think we should at least add a safe version of this e.g.:

func randomBytes(count: Int) -> [UInt8]

as proposed by @lukasa.

This can be implemented on top of the proposed fill(_:) or the other way around.

Alternatively we could also add new API to Array e.g.:

extension Array {
    init<Generator: RandomNumberGenerator>(randomBytesCount: Int, using: inout Generator)
}

A version where one could choose the integer type and range would be nice too but I'm not sure if this can be implement efficiently or if there is even an actually need for that.

2 Likes