Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

bpo-40541: Add optional *counts* parameter to random.sample() #19970

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 10 commits into from
May 8, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Fix typo and improve formatting
  • Loading branch information
rhettinger committed May 8, 2020
commit 1f36ad3c5f2a793eb4c67ac8e5685ce66f764413
9 changes: 6 additions & 3 deletions 9 Lib/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,12 @@ def sample(self, population, k, *, counts=None):

sample(['red', 'red', 'red', 'red', 'blue', 'blue'], k=5)

To choose a sample in a range of integers, use range as an argument.
This is especially fast and space efficient for sampling from a
large population: sample(range(10000000), 60)
To choose a sample from a range of integers, use range() for the
population argument. This is especially fast and space efficient
for sampling from a large population:

sample(range(10000000), 60)

"""

# Sampling without replacement entails tracking either potential
Expand Down
2 changes: 1 addition & 1 deletion 2 Lib/test/test_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def test_sample_with_counts(self):

def test_sample_counts_equivalence(self):
# Test the documented strong equivalence to a sample with repeated elements.
# We run this test on random.Random() which makes deteriministic selections
# We run this test on random.Random() which makes deterministic selections
# for a given seed value.
sample = random.sample
seed = random.seed
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.