gh-108322: Preserve backwards compatibility in NormalDist.samples() when a seed is given#108658
gh-108322: Preserve backwards compatibility in NormalDist.samples() when a seed is given#108658gpshead wants to merge 1 commit intopython:mainfrom
NormalDist.samples() when a seed is given#108658Conversation
…les()` python#108324 switched to a faster implementation, but a caveat is that it changes the specific outputs. This preserves backwards compatibility when the user has asked for specific outputs by supplying a seed value. With an option for them to ask for the new algorithm implementation if desired. When return random values anyway (no seed), the new faster algorithm is used by default.
| @@ -830,8 +830,12 @@ of applications in statistics. | |||
|
|
|||
| .. versionchanged:: 3.13 | |||
There was a problem hiding this comment.
The existing documentation above this says of seed "this is useful for creation reproducible results, even in a multi-threading context." and the PR this is modifying mentions that random.gauss() is problematic describing the non-gauss version as better for being "more self contained and less vulnerable to concurrency issues (because gauss() is stateful between successive calls)."
I presume we might want call that implementation detail out with a sentence added to the above paragraph recommending the new use_gauss=False argument to people if that caveat matters to them? @rhettinger
|
It looks as an over-complication to me. Do you really expect users will use The reproducibility warranty in the The |
|
It could be an over complication. I'm proposing it because this is the kind of conversation that could've happened within the origin unreviewed PR. Taking a look at how often That's another decent indication that caution about behavior changes on this API aren't worthwhile. Thanks! |
#108324 switched to a faster implementation of
statistics.NormalDist.samples(), but a caveat is that it changes the specific outputs.This preserves backwards compatibility when the user has asked for specific outputs by supplying a seed value. With an option for them to ask for the new algorithm implementation if desired.
When returning uniquely random values anyway (no seed), the new faster algorithm is used by default.
📚 Documentation preview 📚: https://cpython-previews--108658.org.readthedocs.build/