> Le 4 oct. 2017 à 19:26, Xiaodi Wu via swift-evolution
> <[email protected]> a écrit :
> To sum up my thoughts so far in code, building on previous comments from
> others, this would be a nice set of random APIs, IMO:
>
> ```
> extension Int {
> static func random(in range: Countable{Closed}Range<Int>) -> Int
> }
> // And similar for other concrete built-in integer types.
> //
> // Since fixed-width integers could exceed the maximum size supported by
> getrandom()
> // and other such functions, we do not provide a default implementation.
> //
> // The return value may not be cryptographically secure if there is
> insufficient entropy.
I don't think that we should limit implementations based on that. If it's not
an issue for `random(byteCount:)`, then it shouldn't be an issue for
FixedWidthInteger.
(Also, I know that getrandom has a threshold where it becomes interruptible,
but I'm not aware of an actual maximum size.)
>
> extension Float {
> static func random(in range: {Closed}Range<Float>) -> Float
> }
>
> extension Double {
> static func random(in range: {Closed}Range<Double>) -> Double
> }
>
> extension Float80 {
> // Ditto.
> }
>
> extension Data {
> static func random(byteCount: Int) -> Data
> }
>
> extension UnsafeMutableRawPointer {
> func copyRandomBytes(count: Int) throws
> }
> // This function is to be the most primitive of the random APIs, and will
> throw if there is insufficient entropy.
>
> extension UnsafeMutableRawBufferPointer {
> func copyRandomBytes() throws
> }
> // Just as UMRBP.copyBytes(from:) parallels UMRP.copyBytes(from:count:), we
> offer this convenience here.
What happened to the collection-based random functions? I'm not incredibly
attached to them, but it doesn't seem to me that anyone has explicitly willed
them away and I just want to be sure that it's not an oversight.
Félix
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution