File tree Expand file tree Collapse file tree 3 files changed +15
-5
lines changed Expand file tree Collapse file tree 3 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -94,7 +94,7 @@ public struct Bool {
94
94
/// method to generate a random Boolean value when you are using a custom
95
95
/// random number generator.
96
96
///
97
- /// let flippedHeads = Boolean .random(using: &myGenerator)
97
+ /// let flippedHeads = Bool .random(using: &myGenerator)
98
98
/// if flippedHeads {
99
99
/// print("Heads, you win!")
100
100
/// } else {
@@ -116,7 +116,7 @@ public struct Bool {
116
116
///
117
117
/// This method returns `true` and `false` with equal probability.
118
118
///
119
- /// let flippedHeads = Boolean .random()
119
+ /// let flippedHeads = Bool .random()
120
120
/// if flippedHeads {
121
121
/// print("Heads, you win!")
122
122
/// } else {
Original file line number Diff line number Diff line change @@ -2577,7 +2577,11 @@ extension ${Range}
2577
2577
// Compute delta, the distance between the lower and upper bounds. This
2578
2578
// value may not representable by the type Bound if Bound is signed, but
2579
2579
// is always representable as Bound.Magnitude.
2580
+ % if 'Closed' in Range:
2580
2581
var delta = Bound . Magnitude ( truncatingIfNeeded: upperBound &- lowerBound)
2582
+ % else :
2583
+ let delta = Bound . Magnitude ( truncatingIfNeeded: upperBound &- lowerBound)
2584
+ % end
2581
2585
% if 'Closed' in Range:
2582
2586
// Subtle edge case: if the range is the whole set of representable values,
2583
2587
// then adding one to delta to account for a closed range will overflow.
@@ -4046,6 +4050,7 @@ public func _assumeNonNegative(_ x: ${Self}) -> ${Self} {
4046
4050
% end
4047
4051
4048
4052
extension ${ Self} {
4053
+ @inlinable
4049
4054
public static func _random< R : RandomNumberGenerator > (
4050
4055
using generator: inout R
4051
4056
) - > ${ Self} {
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ import SwiftShims
32
32
/// }
33
33
///
34
34
/// static func random() -> Weekday {
35
- /// return Weekday.randomWeekday (using: &Random.default)
35
+ /// return Weekday.random (using: &Random.default)
36
36
/// }
37
37
/// }
38
38
///
@@ -60,6 +60,7 @@ public protocol RandomNumberGenerator {
60
60
}
61
61
62
62
extension RandomNumberGenerator {
63
+ @inlinable
63
64
public mutating func _fill( bytes buffer: UnsafeMutableRawBufferPointer ) {
64
65
// FIXME: Optimize
65
66
var chunk : UInt64 = 0
@@ -132,25 +133,29 @@ extension RandomNumberGenerator {
132
133
/// - Apple platforms use `arc4random_buf(3)`.
133
134
/// - Linux platforms use `getrandom(2)` when available; otherwise, they read
134
135
/// from `/dev/urandom`.
136
+ @_fixed_layout
135
137
public struct Random : RandomNumberGenerator {
136
138
/// The default instance of the `Random` random number generator.
139
+ @inlinable
137
140
public static var `default` : Random {
138
141
get { return Random ( ) }
139
142
set { /* Discard */ }
140
143
}
141
144
142
- private init ( ) { }
145
+ @inlinable
146
+ internal init ( ) { }
143
147
144
148
/// Returns a value from a uniform, independent distribution of binary data.
145
149
///
146
150
/// - Returns: An unsigned 64-bit random value.
147
- @effects ( releasenone )
151
+ @inlinable
148
152
public mutating func next( ) -> UInt64 {
149
153
var random : UInt64 = 0
150
154
_stdlib_random ( & random, MemoryLayout< UInt64> . size)
151
155
return random
152
156
}
153
157
158
+ @inlinable
154
159
public mutating func _fill( bytes buffer: UnsafeMutableRawBufferPointer ) {
155
160
if !buffer. isEmpty {
156
161
_stdlib_random ( buffer. baseAddress!, buffer. count)
You can’t perform that action at this time.
0 commit comments