[Tutor] about random seed

linda.s samrobertsmith at gmail.com
Sun Sep 3 08:22:16 CEST 2006


On 9/2/06, Bob Gailer <bgailer at alum.rpi.edu> wrote:
> linda.s wrote:
> > I read something about random.seed() but still confused. i can
> > understand random.random() but it is very hard for me to understand
> > random.seed(0... can anyone explain an example?
> >
> I suggest you read
> http://en.wikipedia.org/wiki/Pseudorandom_number_generator to get the
> gist of pseudorandom number generation. Section 4 Mersenne twister
> <http://en.wikipedia.org/wiki/Pseudorandom_number_generator#Mersenne_twister>
> is the algorithm used by Python random.
>
> random.seed() sets the starting number for the generator. Setting the
> seed to a known value can be important if you want the same sequence of
> pseudorandom numbers to be generated each time you test/run your
> program. Note that in Python "the current system time is ... used to
> initialize the generator when the [random] module is first imported."
> This pretty well ensures that the sequence of numbers generated will be
> different each time.
>
I still can not understand. can you show me an example?
Thanks!
Linda


More information about the Tutor mailing list