[SciPy-user] Generating and Sampling Random Numbers

Alan G Isaac aisaac at american.edu
Thu Oct 11 17:57:11 EDT 2007


On Thu, 11 Oct 2007, Lorenzo Isella apparently wrote:
> Here is my problem: in general I should not call e.g. 
> stats.norm.rvs at every time step, since it amounts to 
> continually re-initializing the random number generator, 
> and any generator is guaranteed to have good "randomness" 
> only within a sequence. Instead frequent initializations, 
> i.e. many independent callings rather than generating 
> a single long sequence, may introduce some correlations in 
> the sampled numbers.  However, it is rather cumbersome to 
> do something like:
> my_random=stats.norm.rvs(size=100000, loc=0.)
> and then read a number from the my_random array at every time step while 
> also keeping track of the position of the last read number 
> on the array.  Is there any better way of doing this? 


I am not sure I grok your concern,
but perhaps what you want is to look at
help(numpy.random.seed)
You can make your own RNG instance and seed it.

If you did do it the other way you suggested
(but there is no need as far as I can tell),
just use a 2d shape and iterate over it.
(Assuming you are not losing particles.)

Cheers,
Alan Isaac






More information about the SciPy-User mailing list