Mike wrote:
....
I have a question about the function rand().
Let say we have a variable $a = int (rand(50)), is there a formula that can
predict how long this random function will hit all the values from 0 to 49?
(Assume srand is set to a fixed value)
It is unclear what you are actually asking. The given expression will
always generate integer values between 0 and 49, so perhaps you are
looking for "forever"?
Or do you mean something like "What is the expected value of X, where X
is the number of iterations which occur of a uniformly distributed
integer random variable over the range 0 to 49 inclusive when all 50
possible values are finally generated by the sequence?" If that is what
you mean, you have a statistical question, not a Perl question. If
that's your question, try asking in a statistics newsgroup. Or run a
Monte Carlo experiment.
Also, I'm not sure what you mean by "assume srand is set to a fixed
value"? You're not calling srand() with the same argument every time
you are calling rand() are you? These days one doesn't ever need to
call srand() unless one wishes to get exactly the same pseudorandom
sequence each time the program is executed -- and then, one would call
srand() only once, at the start of the program. If srand() is called
with a fixed value, the pseudorandom sequence returned by rand() will
start over at the same point each time srand() is called. See:
perldoc -f srand
perldoc -f rand
....