On May 30, drieux said:

>> srand;
>> $RandomScript = $Scripts[int(rand(@Scripts))];
>>
>       my $RandomScript = $Scripts[int(rand($#Scripts + 1))];
>
>I am also a bit concerned with trying to seed rand() with a
>list, rather than say, the count of the list as noted above.
>
>never be afraid to step aside, whip out a silly bit in YourTmpDirHere
>and bash the semantics till it does what you really want...
>since you do recall that it provides for a random value
>from 0 to less than expr - hence you want (index + 1) so
>that you can get your last element in the list....

Don't worry.  rand() requires its argument to be a scalar, so rand(@x) is
like rand(scalar @x) (which is for all intents and purposes rand($#x+1)).

I'm more concerned about the use of srand(), which is superfluous in
recent Perls.  The int() is also superfluous.

  $element = @things[rand @things];

-- 
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