Skip to content

Commit 41b33df

Browse files
Update random docs to SystemRandomNumberGenerator (#18043)
1 parent 5fdf107 commit 41b33df

File tree

5 files changed

+22
-27
lines changed

5 files changed

+22
-27
lines changed

stdlib/public/core/Collection.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,9 +1053,8 @@ extension Collection {
10531053
/// let randomName = names.randomElement()!
10541054
/// // randomName == "Amani"
10551055
///
1056-
/// This method uses the default random generator, `Random.default`. The call
1057-
/// to `names.randomElement()` above is equivalent to calling
1058-
/// `names.randomElement(using: &Random.default)`.
1056+
/// This method is equivalent to calling the version that takes a generator,
1057+
/// passing in the system's default random generator.
10591058
///
10601059
/// - Returns: A random element from the collection. If the collection is
10611060
/// empty, the method returns `nil`.

stdlib/public/core/CollectionAlgorithms.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,8 @@ extension Sequence {
407407
/// let shuffledNumbers = numbers.shuffled()
408408
/// // shuffledNumbers == [1, 7, 6, 2, 8, 9, 4, 3, 5, 0]
409409
///
410-
/// This method uses the default random generator, `Random.default`. The call
411-
/// to `numbers.shuffled()` above is equivalent to calling
412-
/// `numbers.shuffled(using: &Random.default)`.
410+
/// This method is equivalent to calling the version that takes a generator,
411+
/// passing in the system's default random generator.
413412
///
414413
/// - Returns: A shuffled array of this sequence's elements.
415414
///
@@ -465,9 +464,8 @@ extension MutableCollection where Self : RandomAccessCollection {
465464
/// names.shuffle(using: myGenerator)
466465
/// // names == ["Luis", "Camila", "Luciana", "Sofía", "Alejandro", "Diego"]
467466
///
468-
/// This method uses the default random generator, `Random.default`. The call
469-
/// to `names.shuffle()` above is equivalent to calling
470-
/// `names.shuffle(using: &Random.default)`.
467+
/// This method is equivalent to calling the version that takes a generator,
468+
/// passing in the system's default random generator.
471469
///
472470
/// - Complexity: O(*n*)
473471
@inlinable

stdlib/public/core/FloatingPoint.swift.gyb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2502,9 +2502,8 @@ where Self.RawSignificand : FixedWidthInteger {
25022502
/// of `range`, some concrete values may be represented more frequently than
25032503
/// others.
25042504
///
2505-
/// This method uses the default random generator, `Random.default`. The call
2506-
/// to `Double.random(in: ${exampleRange})` above is equivalent to calling
2507-
/// `Double.random(in: ${exampleRange}, using: &Random.default)`.
2505+
/// This method is equivalent to calling the version that takes a generator,
2506+
/// passing in the system's default random generator.
25082507
///
25092508
/// - Parameter range: The range in which to create a random value.
25102509
% if Range == 'Range':

stdlib/public/core/Integers.swift.gyb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2618,9 +2618,8 @@ extension FixedWidthInteger {
26182618
/// // Prints "64"
26192619
/// // Prints "5"
26202620
///
2621-
/// This method uses the default random generator, `Random.default`. The call
2622-
/// to `Int.random(in: ${exampleRange})` above is equivalent to calling
2623-
/// `Int.random(in: ${exampleRange}, using: &Random.default)`.
2621+
/// This method is equivalent to calling the version that takes a generator,
2622+
/// passing in the system's default random generator.
26242623
///
26252624
/// - Parameter range: The range in which to create a random value.
26262625
% if Range == 'Range':

stdlib/public/core/Random.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import SwiftShims
2121
///
2222
/// When providing new APIs that use randomness, provide a version that accepts
2323
/// a generator conforming to the `RandomNumberGenerator` protocol as well as a
24-
/// version that uses the default generator. For example, this `Weekday`
24+
/// version that uses the default system generator. For example, this `Weekday`
2525
/// enumeration provides static methods that return a random day of the week:
2626
///
2727
/// enum Weekday: CaseIterable {
@@ -32,7 +32,8 @@ import SwiftShims
3232
/// }
3333
///
3434
/// static func random() -> Weekday {
35-
/// return Weekday.random(using: &Random.default)
35+
/// var g = SystemRandomGenerator()
36+
/// return Weekday.random(using: &g)
3637
/// }
3738
/// }
3839
///
@@ -110,12 +111,11 @@ extension RandomNumberGenerator {
110111
}
111112
}
112113

113-
/// The default source of random data.
114+
/// The system's default source of random data.
114115
///
115116
/// When you generate random values, shuffle a collection, or perform another
116-
/// operation that depends on random data, this type's `default` property is the
117-
/// generator used by default. For example, the two method calls in this example
118-
/// are equivalent:
117+
/// operation that depends on random data, this type is the generator used by
118+
/// default. For example, the two method calls in this example are equivalent:
119119
///
120120
/// let x = Int.random(in: 1...100)
121121
/// var g = SystemRandomNumberGenerator()
@@ -125,13 +125,13 @@ extension RandomNumberGenerator {
125125
/// multiple threads, and uses a cryptographically secure algorithm whenever
126126
/// possible.
127127
///
128-
/// Platform Implementation of `Random`
129-
/// ===================================
128+
/// Platform Implementation of `SystemRandomNumberGenerator`
129+
/// ========================================================
130130
///
131-
/// While the `SystemRandomNumberGenerator` generator is automatically seeded
132-
/// and thread-safe on every platform, the cryptographic quality of the stream
133-
/// of random data produced by the generator may vary. For more detail, see the
134-
/// documentation for the APIs used by each platform.
131+
/// While the system generator is automatically seeded and thread-safe on every
132+
/// platform, the cryptographic quality of the stream of random data produced by
133+
/// the generator may vary. For more detail, see the documentation for the APIs
134+
/// used by each platform.
135135
///
136136
/// - Apple platforms use `arc4random_buf(3)`.
137137
/// - Linux platforms use `getrandom(2)` when available; otherwise, they read

0 commit comments

Comments
 (0)