File tree Expand file tree Collapse file tree 1 file changed +5
-3
lines changed Expand file tree Collapse file tree 1 file changed +5
-3
lines changed Original file line number Diff line number Diff line change @@ -2106,11 +2106,13 @@ extension BinaryFloatingPoint {
2106
2106
/// - Returns: A random representation of this floating point conforming to
2107
2107
/// `Randomizable`
2108
2108
///
2109
- /// The range of this random floating point is from 0 to 1 inclusive
2109
+ /// The range of this random floating point is from 0 to 1 exclusive
2110
2110
@_inlineable
2111
2111
public static func random< T: RandomNumberGenerator > ( using generator: T ) -> Self {
2112
- let random = generator. next ( UInt64 . self)
2113
- return Self ( random) / Self( UInt64 . max)
2112
+ let bits = MemoryLayout < Self > . size * 8
2113
+ let fraction = bits - Self. exponentBitCount
2114
+ let random = generator. next ( UInt64 . self) >> ( bits - fraction)
2115
+ return Self ( random) / Self( 1 << fraction)
2114
2116
}
2115
2117
2116
2118
/* TODO: uncomment these default implementations when it becomes possible
You can’t perform that action at this time.
0 commit comments