Skip to content

Commit 33c2efe

Browse files
Update random docs to SystemRandomNumberGenerator (#18042)
1 parent d8e9bff commit 33c2efe

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
@@ -1044,9 +1044,8 @@ extension Collection {
10441044
/// let randomName = names.randomElement()!
10451045
/// // randomName == "Amani"
10461046
///
1047-
/// This method uses the default random generator, `Random.default`. The call
1048-
/// to `names.randomElement()` above is equivalent to calling
1049-
/// `names.randomElement(using: &Random.default)`.
1047+
/// This method is equivalent to calling the version that takes a generator,
1048+
/// passing in the system's default random generator.
10501049
///
10511050
/// - Returns: A random element from the collection. If the collection is
10521051
/// empty, the method returns `nil`.

stdlib/public/core/CollectionAlgorithms.swift

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

stdlib/public/core/FloatingPoint.swift.gyb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2488,9 +2488,8 @@ where Self.RawSignificand : FixedWidthInteger {
24882488
/// of `range`, some concrete values may be represented more frequently than
24892489
/// others.
24902490
///
2491-
/// This method uses the default random generator, `Random.default`. The call
2492-
/// to `Double.random(in: ${exampleRange})` above is equivalent to calling
2493-
/// `Double.random(in: ${exampleRange}, using: &Random.default)`.
2491+
/// This method is equivalent to calling the version that takes a generator,
2492+
/// passing in the system's default random generator.
24942493
///
24952494
/// - Parameter range: The range in which to create a random value.
24962495
% if Range == 'Range':

stdlib/public/core/Integers.swift.gyb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2591,9 +2591,8 @@ extension FixedWidthInteger {
25912591
/// // Prints "64"
25922592
/// // Prints "5"
25932593
///
2594-
/// This method uses the default random generator, `Random.default`. The call
2595-
/// to `Int.random(in: ${exampleRange})` above is equivalent to calling
2596-
/// `Int.random(in: ${exampleRange}, using: &Random.default)`.
2594+
/// This method is equivalent to calling the version that takes a generator,
2595+
/// passing in the system's default random generator.
25972596
///
25982597
/// - Parameter range: The range in which to create a random value.
25992598
% 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)