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
Prev Previous commit
Next Next commit
Add exact equidistribution test
  • Loading branch information
rhettinger committed May 7, 2020
commit 672f739050b398b806a798eb598fa2eace391790
5 changes: 5 additions & 0 deletions 5 Lib/test/test_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ def test_sample_with_weights(self):
summary = Counter(sample(['x'], weights=[10], k=8))
self.assertEqual(summary, Counter(x=8))

# Case with all weights equal.
nc = len(colors)
summary = Counter(sample(colors, weights=[10]*nc, k=10*nc))
self.assertEqual(summary, Counter(10*colors))

# Test error handling
with self.assertRaises(TypeError):
sample(['red', 'green', 'blue'], weights=10, k=10) # weights not iterable
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.