On Sun, Aug 05, 2001 at 07:31:45AM -1000, . wrote:
> > Before 5.004 you did need to seed the PRNG, but I'm not convinced that
> > time|$$ was ever a really good choice. Good enough for most purposes
> > though, if called only once.
>
> But why only once? That's the part that confusses me.
I think this has been explained well by Gary Stainburn.
> > > But this only produces a psedo random number. Thus only a subset of the
> > > possible numbers will ever be invoked, and in a certain sequence at
> that.
> >
> > Well, that depends on how good your PRNG is. And the sequence depends
> > on the seed you choose. I suspect that in general, perl will choose a
> > better seed than you, but check out pp.c if you want to see the gory
> > details.
>
> Where do I find it? In the perldocs/manpages someplace?
pp.c is a part of the Perl source code.
> > Are pseudo random numbers not good enough for you? What do you want to
> > do - high grade crytography?
>
> No, but giving it some arbitrary integer range isn't sufficient, either
> since only a fraction of the numbers would ever get used. Here's an example
> of what I'm doing with this (pseudocode):
>
> done = false
> while !done {
> number = random_number
> if number is not in set_of_numbers {
> add number to set_of_numbers
> done = true
> }
> }
>
> So what happens if the PRNG starts repeating values? Like what would happen
> pretty quickly with:
>
> rand 100
>
> It get's caught in an infinite loop. If you re-seed each pass through the
> loop, then the only way it will get caught is if all possible numbers are
> taken. It might get a little slow once most of the numbers have been taken,
> but it won't get stuck that way. That is, unless you're using another PRNG
> to seed it, say with:
>
> rand(rand*100)
>
> In fact, both mathematically and from my own experience, this will have the
> effect of reducing the randomness of the number gereration. Hence, time is
> an efficient seed because it's constantly changing in a way that's
> theoretically impossible to repeat. (Unless you know of a way to make a
> computer's internal clock start to move backwards w/o adversely affecting
> the system. :)
OK. You are getting very confused and making this an awful lot harder
than it needs to be. A PRNG *will* repeat values. If 100 calls to
int rand(100) produced the numbers 0-99 then it wouldn't be very random.
The PRNG will not get caught in an infinite loop. At least not for a
very long time if it is any good. You shouldn't re-seed it. A lot of
clever people have arranged things such that it is very easy to get
reasonable random numbers for general use. Don't subvert their work
unless you know what you are doing and why.
Try this:
#!/usr/bin/perl
print int rand 100, "\n" while 1;
__END__
Look at the output and tell us how long it takes for the pattern to
repeat. That should kill this thread for a while ;-)
--
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]