Skip to content

bpo-42944 Fix Random.sample when counts is not None#24235

Merged
rhettinger merged 5 commits intopython:masterfrom
jonanifranco:master
Jan 18, 2021
Merged

bpo-42944 Fix Random.sample when counts is not None#24235
rhettinger merged 5 commits intopython:masterfrom
jonanifranco:master

Conversation

@jonanifranco
Copy link
Contributor

@jonanifranco jonanifranco commented Jan 17, 2021

Replace [Random.]sample by self.sample in Random.sample path when count is not None to correctly use instance generator instead of module generator.
@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA).

CLA Missing

Our records indicate the following people have not signed the CLA:

@jonanifranco

For legal reasons we need all the people listed to sign the CLA before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

If you have recently signed the CLA, please wait at least one business day
before our records are updated.

You can check yourself to see if the CLA has been received.

Thanks again for the contribution, we look forward to reviewing it!

@rhettinger
Copy link
Contributor

  • Please sign the contributor agreement (CLA).
  • Add a test that fails before the PR and passes afterward.
  • Add a Misc/NEWS entry using Blurb.

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, that there is a test which should catch this bug, but it does not work because it tests only global random.sample().

Please replace random with self.gen in test_sample_counts_equivalence and move that method to MersenneTwister_TestBasicOps, because it does not make sense for SystemRandom.

@jonanifranco
Copy link
Contributor Author

I had just updated my master branch with a new test before reading @serhiy-storchaka comment. I update again test_random.py as suggested.

test_sample_counts_equivalence should catch bpo-42944, but it does not work because it tests only global random.sample.
random is replaced by self.gen in test_sample_counts_equivalence and that method is moved to MersenneTwister_TestBasicOps, because it does not make sense for SystemRandom
@rhettinger
Copy link
Contributor

Please add an entry to Misc/NEWS.

@jonanifranco
Copy link
Contributor Author

Please add an entry to Misc/NEWS.

Done.
I also signed the CLA yesterday.

@rhettinger rhettinger merged commit f7b5bac into python:master Jan 18, 2021
@miss-islington
Copy link
Contributor

Thanks @jonanifranco for the PR, and @rhettinger for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jan 18, 2021
@bedevere-bot
Copy link

GH-24243 is a backport of this pull request to the 3.9 branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants