[SciPy-dev] random seed in scipy.stats
Sun Apr 20 02:14:31 CDT 2008
On Sat, Apr 19, 2008 at 5:48 PM, Hoyt Koepke <email@example.com> wrote:
> I may have missed something here, so I'll first ask: Is there a way to
> specify a random number seed in scipy.stats? I'm building a project
> using it which requires exactly reproducible distribution samples, so
> being able to specify a random seed is a must.
> I've been looking around in the code, and I don't see a way to do it.
> Even if it is there, it calls numpy.random directly, which would not
> work reliably.
numpy.random.seed() is exposed, although I only recommend using it to
work around poorly designed APIs like the one in scipy.stats.
> However, it seems that it'd be easy to add in by initializing a
> RandomState object in the constructors of both rv_continuous and
> rv_discrete, seeding it using an optional kw arg that defaults to
> None. All the code that currently draws samples from numpy.random
> directly would then draw samples from this. As far as I can see, this
> wouldn't break backwards compatibility and would add in a useful
> feature. The only change (I think) would be to distributions.py.
> Have I missed anything? If this is acceptable, I'll gladly make the
> change and post a diff and a unit test.
My preference is for a pattern like this:
def somefunc(x,y,z, prng=numpy.random):
w = prng.standard_normal()
This allows the default uses to share the same generator state which
could avoid some problematic cases.
But yes, such a change would be very welcome. It might be a
substantial chunk of work, though, which is why I haven't done it.
"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