[SciPy-dev] random seed in scipy.stats

Robert Kern robert.kern@gmail....
Sun Apr 20 19:30:43 CDT 2008

On Sun, Apr 20, 2008 at 3:23 PM, Hoyt Koepke <hoytak@gmail.com> wrote:
> Okay, I'm planning to add this to the stats module this afternoon, and
>  I need to check with people on the best way to include the new random
>  number features.
>  Option 1:
>  Allow two additional keyword arguments to the constructor and to the
>  rvs functions, namely randseed and prng.  If neither are given, it
>  would default to the current behavior and draw straight from
>  numpy.random.  If randseed is given, but not prng, it would create a
>  random state object with that seed.  prng would be a RandomState
>  object from numpy.random; if given randseed is ignored and that is
>  used to draw the random numbers.  Any concerns?
>  Option 2:
>  have a single additional kw arg like rnginfo or randominfo.  If it's a
>  RandomState instance, it is used to draw numbers from.  If it's
>  anything else, it's used to seed the random number generator.  If it's
>  None, it's discarded.

I prefer just being able to pass in a RandomState object. It's a
subtle encouragement to do the right thing, which is to share a single
RandomState object. People who *really* want to just pass in a seed
just need to wrap that seed with RandomState(seed). "There should be
one-- and preferably only one --obvious way to do it."

>  With both options, arguments to the rvs method would override the
>  arguments to the constructor, but only for that function call.
>  I would personally go for 1., as it seems the potential for API
>  confusion is a lot less.  Also, 2 wouldn't allow people to pass in
>  arbitrary random number generating objects that defined the correct
>  methods, whereas 1 would (though this would probably be pretty rare).
>  Now if we do 1, is prng the best argument name for the randomstate
>  object?  I could also use rso, rng, randomstateobject, etc.

<shrug> I like it. I think it's the best mix of terseness and comprehensibility.

Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
 -- Umberto Eco

More information about the Scipy-dev mailing list