in reply to Randomly picking numbers

another way of getting random number
@arr = (1,2,13,40,5,6,7,100,34,); print $arr[int rand(@arr)]."\n";
!!@!!
May the force be with you!!

Replies are listed 'Best First'.
Re^2: Randomly picking numbers
by gellyfish (Monsignor) on May 05, 2005 at 12:38 UTC

    You don't need the int as the subscript is always an integer therefore the index is implicitly converted before being used.

    /J\

      ...the index is implicitly converted before being used.

      ...and it does so via truncation:

      % perl -le 'print +(0, 1)[0.999999]' 0
      as opposed to rounding, and that's why it works so well in $arr[rand @arr].

      the lowliest monk