Loading ...
Sorry, an error occurred while loading the content.

Random Number

Expand Messages
  • snipa_hawk
    In C++ to set a variable to a rand number you use =rand % (number of highest). Is there a similar command in Perl. Thanks.
    Message 1 of 2 , Jul 31, 2003
    • 0 Attachment
      In C++ to set a variable to a rand number you use <variable>=rand %
      (number of highest). Is there a similar command in Perl. Thanks.
    • Damien Carbery
      ... It seems like you didn t read (didn t bother maybe??) about the srand and rand perl functions that Jeff mentioned in post 16022
      Message 2 of 2 , Aug 1, 2003
      • 0 Attachment
        --- In perl-beginner@yahoogroups.com, "snipa_hawk" <snipa_hawk@y...>
        wrote:
        > In C++ to set a variable to a rand number you use <variable>=rand %
        > (number of highest). Is there a similar command in Perl. Thanks.

        It seems like you didn't read (didn't bother maybe??) about the srand
        and rand perl functions that Jeff mentioned in post 16022
        http://groups.yahoo.com/group/perl-beginner/message/16022

        Here's a link to info on rand so you don't even have to type anything:
        http://www.perldoc.com/perl5.8.0/pod/func/rand.html

        It has an example of getting a random integer betweeen 0 and 9:
        int(rand(10))
        Simply add 1 to get numbers between 1 and 10.
        Drop the 'int' if you want fractional numbers.
      Your message has been successfully submitted and would be delivered to recipients shortly.