On Jul 17, Jilani, Mohammad K said:

>How can I generate a whole number betwee 10 - 99?

Well, using int(rand(10)) gives you an integer from 0 to 9.  If you add 10
to it, you get an integer from 10 to 19.

To get an integer from 10 to 99, you need to come up with an expression of
the form

  X + int(rand(Y))

We know X is going to be 10 (because 10 is the lowest number to be
returned.  So subtracting 10 from our endpoints, we go from 10 and 99 to 0
and 89.  So for int(rand(Y)) to return a number from 0 to 89, Y must be
90.

  $num = 10 + int rand 90;

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to