Re: rand()
- From: Jim Gibson <jimsgibson@xxxxxxxxx>
- Date: Mon, 28 Jul 2008 09:06:39 -0700
In article <532078.84144.qm@xxxxxxxxxxxxxxxxxxxxxxxxxxx>, Bobby
<cybercruiserz@xxxxxxxxx> wrote:
Hi all,
Ý
How do I use the rand function to print out more than one random number for
an array? In the example scriptÝbelow i haveÝan array @nums with a list of
numbers; howÝdo i print out more than one random numbers from that list
(@nums)? Thanks.
Ý
#!/usr/bin/perl
use strict;
use warnings;
my @nums = ("10000","10002","10004","10005","10006","140000","1500000");
my $randnum = $nums[rand(@nums)];
print "$randnum \n";
Use a loop:
for ( 1..5 ) [
my $randnum = $nums[rand(@nums)];
print "$randnum \n";
}
--
Jim Gibson
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
http://www.usenet.com
.
- References:
- rand()
- From: Bobby
- rand()
- Prev by Date: Re: rand()
- Next by Date: Re: rand()
- Previous by thread: Re: rand()
- Next by thread: Re: rand()
- Index(es):
Relevant Pages
|