@@ -95,7 +95,7 @@ unstable implementation of `randomSample` explicitly shuffles the elements
95
95
before returning them.
96
96
97
97
To see the bias without shuffling, consider the following example that uses a
98
- hypothetical ` randomElementsUnshuffled ` method. When selecting three out of
98
+ hypothetical ` randomSampleUnshuffled ` method. When selecting three out of
99
99
four elements from an array, whenever any of the first three elements are
100
100
included in the result, they are always in their original positions. Elements
101
101
selected after the initial ` count ` are in randomly selected positions.
@@ -104,19 +104,19 @@ selected after the initial `count` are in randomly selected positions.
104
104
// This shows the behavior WITHOUT post-sample shuffling.
105
105
// Selecting 3/4 elements, there are only four possible outcomes:
106
106
let source = [10 , 20 , 30 , 40 ]
107
- source.randomElementsUnshuffled (count : 3 ) // [10, 20, 30]
108
- source.randomElementsUnshuffled (count : 3 ) // [40, 20, 30]
109
- source.randomElementsUnshuffled (count : 3 ) // [10, 40, 30]
110
- source.randomElementsUnshuffled (count : 3 ) // [10, 20, 40]
107
+ source.randomSampleUnshuffled (count : 3 ) // [10, 20, 30]
108
+ source.randomSampleUnshuffled (count : 3 ) // [40, 20, 30]
109
+ source.randomSampleUnshuffled (count : 3 ) // [10, 40, 30]
110
+ source.randomSampleUnshuffled (count : 3 ) // [10, 20, 40]
111
111
```
112
112
113
- The proposed ` randomElements ` method has no positional bias:
113
+ The proposed ` randomSample ` method has no positional bias:
114
114
115
115
``` swift
116
116
// The current behavior shuffles the elements, erasing the bias:
117
117
let source = [10 , 20 , 30 , 40 ]
118
- source.randomElements (count : 3 ) // [20, 30, 10]
119
- source.randomElements (count : 3 ) // [40, 20, 30]
118
+ source.randomSample (count : 3 ) // [20, 30, 10]
119
+ source.randomSample (count : 3 ) // [40, 20, 30]
120
120
// ...several more possible outcomes
121
121
```
122
122
0 commit comments