[Python-ideas] Python's Source of Randomness and the random.py module Redux
Steven D'Aprano
steve at pearwood.info
Fri Sep 11 17:41:25 CEST 2015
Random832,
You appear to have edited the subject line to remove the word "DRAFT".
As I explained in an earlier post, that message was a draft and not
intended to go to the list.
Nevertheless, I will respond to your question below.
On Fri, Sep 11, 2015 at 10:23:52AM -0400, random832 at fastmail.us wrote:
> On Fri, Sep 11, 2015, at 09:36, Steven D'Aprano wrote:
> > Yes, calling `random.choice` is *significantly better* than calling
> > `random.SomethingRandom().choice`. It's better for beginners, it's even
> > better for expert users whose random needs are small, and those whose
> > needs are greater shouldn't be using the later anyway.
>
> Why is it that people who need deterministic/seed based random aren't
> considered to be "those whose needs are greater"?
I didn't say that. Read again: I give three groups of people:
- Beginners, who are best served by calling `random.choice` rather than
`random.SomethingRandom().choice`.
- Those who are experts *and also* have "small" needs. I didn't define
"small needs" because (1) I thought it was obvious in context and (2)
the post was a draft and still in progress. What I mean by small needs
is that they don't care about reproducibility, security, or having
multiple independent PRNGs.
- Those who *do* have "greater" needs, whether expert or not. Again, I
thought in context it would be clear that greater needs includes such
things as reproducibility, security or multiple independent PRNGs.
In no case that I know of is it a good thing to be creating a brand-new
instance for each and every call to the PRNG. At best, it is harmless,
and only a little inefficient. At worst, it is a lot inefficient, and
potentially may affect the reproducibility, security or statistical
properties of the random numbers you generate.
--
Steve
More information about the Python-ideas
mailing list