Question

M

Mike

Hi,

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)

thanks,
Mike
 
B

Brian McCauley

Mike said:
Subject: Question

I have a question about the function rand().

Please put the subject of your post in the subject of your post.
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)

Not if the random number generator is any good.

This, of course, has nothing to do with Perl.
 
B

Bob Walton

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

....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,150
Latest member
MakersCBDReviews
Top