[root@web-db masterbash]# cat perl.pl
#!/usr/bin/perl -w
use strict;
open(my $OUT,">>random_num.txt");
my @step = ();
while (1){
my $num= int (rand(200)+1); #所取随机数范围!
my $i = 0;
foreach my $step (@step){
if ($step eq $num){
$i = 1;
last;
}
}
if ($i == 0){
push (@step, $num);
}
my $k = $#step + 1;
if ($k == 200){ #所要的随机数个数!!
print $OUT "@step\n";
last;
}
}
[root@web-db masterbash]#
该脚本不错,对于产生成千上万并且不重复的随机数效率还是蛮高的。
阅读(386) | 评论(0) | 转发(0) |