Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Subject
- Posted on
- Question
- 09-09-2004
Re: Question
> 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.
Re: Question
^^ Hi,
^^
^^ I have a question about the function rand().
Why didn't you put that in the title?
^^ 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?
Considering that it never will return anything but integer values 0 to 49
inclusive, I'd say the answer is "forever".
It'll loop though.
Abigail
--
# Perl 5.6.0 broke this.
%0=mapABC,ACB,BAC,BCA,CAB,CBA;$_=shift().AC;1while+s/(\d+)((.)
(.))/($0=$1-1)?"$0$3$01$2$0$0$4":"$3 => $4\n"/xeg;print#Towers of Hanoi
Re: Question
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
....
> Mike
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
....
> 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
....
> Mike
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
Site Timeline
- » FAQ 1.3 Which version of Perl should I use?
- — Next thread in » PERL Discussions
- » Sybase DBI Returned data query
- — Previous thread in » PERL Discussions
- » s suffix question
- — Newest thread in » PERL Discussions
- » Dell Battery Slice LED codes
- — The site's Newest Thread. Posted in » Laptop Computers Forum