[Tutor] Generating random numbers

Venkatesh Babu venkatbabukr at yahoo.com
Thu Dec 4 23:54:31 EST 2003


Hi,

Just wanted to clarify my point once again.

So, do u mean to say that in a single thread, the
following sequence of calls are OK:

random.gauss(50, 5)
random.gauss(50, 5)
... Some code....
random.gauss(25, 4)
random.gauss(25, 4)
... Some more code....
random.gauss(50, 5)
random.gauss(50, 5)

Because till now I was thinking that generation of
random numbers following a probability distribution
should maintain some history information.

Thank you,
Venkatesh

--- Tim Peters <tim.one at comcast.net> wrote:
> [Venkatesh Babu]
> > I have a question related to generation of random
> > numbers based on some probability distribution
> >
> > In my simulation program I have to generate random
> > numbers based on same kind of distribution, say
> normal
> > distribution, but for different independent
> purposes:
> > like determining number of agents in a place,
> > determination ages of each agent. So, there are
> more
> > than one normal distributions, each having its own
> > mean and variance. In such a situation I guess we
> > should create "Random" objects corresponding to
> each
> > purpose and call normalvariate function of these
> > objects with the corresponding mean and variance.
> >
> > Is the above method proper or can we do away by
> just
> > calling the normalvariate function given in the
> random
> > module instead of creating "Random" objects.
> 
> Calling random.normalvariate(mu, sigma) for all
> purposes is fine (although
> calling random.gauss(mu, sigma) is faster -- gauss()
> was added after
> normalvariate(), and normalvariate() sticks around
> so that older programs
> using it can continue to get bit-for-bit identical
> results).
> 
> The only really good reason to create your own
> Random objects is if you're
> running multiple threads, in which case having each
> thread use its own
> Random object makes it very much easier to get
> exactly reproducible (across
> distinct program runs) results.
> 


__________________________________
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
http://companion.yahoo.com/



More information about the Tutor mailing list