Skip to content

Fix method name in Random Sampling guide #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 12, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Guides/RandomSampling.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ unstable implementation of `randomSample` explicitly shuffles the elements
before returning them.

To see the bias without shuffling, consider the following example that uses a
hypothetical `randomElementsUnshuffled` method. When selecting three out of
hypothetical `randomSampleUnshuffled` method. When selecting three out of
four elements from an array, whenever any of the first three elements are
included in the result, they are always in their original positions. Elements
selected after the initial `count` are in randomly selected positions.
Expand All @@ -104,19 +104,19 @@ selected after the initial `count` are in randomly selected positions.
// This shows the behavior WITHOUT post-sample shuffling.
// Selecting 3/4 elements, there are only four possible outcomes:
let source = [10, 20, 30, 40]
source.randomElementsUnshuffled(count: 3) // [10, 20, 30]
source.randomElementsUnshuffled(count: 3) // [40, 20, 30]
source.randomElementsUnshuffled(count: 3) // [10, 40, 30]
source.randomElementsUnshuffled(count: 3) // [10, 20, 40]
source.randomSampleUnshuffled(count: 3) // [10, 20, 30]
source.randomSampleUnshuffled(count: 3) // [40, 20, 30]
source.randomSampleUnshuffled(count: 3) // [10, 40, 30]
source.randomSampleUnshuffled(count: 3) // [10, 20, 40]
```

The proposed `randomElements` method has no positional bias:
The proposed `randomSample` method has no positional bias:

```swift
// The current behavior shuffles the elements, erasing the bias:
let source = [10, 20, 30, 40]
source.randomElements(count: 3) // [20, 30, 10]
source.randomElements(count: 3) // [40, 20, 30]
source.randomSample(count: 3) // [20, 30, 10]
source.randomSample(count: 3) // [40, 20, 30]
// ...several more possible outcomes
```

Expand Down