[SciPy-user] random numbers in scipy
Mon Apr 23 11:30:46 CDT 2007
Giovanni Samaey wrote:
> Thanks for the (short) answer:
> 1. Only numpy.random has a "random.seed". So I assume I should be using
> that module, and not scipy.stats?
If it has the distributions that you need. If you need distributions that are
only provided by the distribution objects in scipy.stats, then you might need to
> 2. Do I seed the module, or an instance of something (as in pygsl)?
> The method is not described in the numpy book, and the docstring says
> it is a method of mtrand.RandomState, which is an object. I deduce from
> this that the module initialises one single object of this type on
> import, which is used by every call to generate a random number, for any
> distribution? Is this a right deduction?
The "functions" in numpy.random are just aliases to the methods on the global
instance. They are there only for convenience when you don't need real control
over the stream and for backwards compatibility with Numeric's RandomArray which
only had global state.
The preferred way is to make your own instance of RandomState and call methods
off of it. You should only use numpy.random.seed() if you need to work around
other code which uses the global instance (which, unfortunately, is much of
"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-user