可以快速产生大量随机数据,进行程序比对,查错
#!/usr/bin/perl
my $seed=10000;
=cut
$i=0;
while (1) {
$no = int(rand($countoflines));
print $no;
print "\n";
if (!$rand{$no})
{
$rand{$no}=1;
$i++;
}
last if ($i>=500);
}
@randnum = keys %rand;
=cut
# 这个是boj1410的随机数据生成函数
&generate();
sub generate
{
my $tcase = get_rand_num(100);
$tcase = 100;
printf "%s\n", $tcase;
foreach (1..$tcase)
{
my $cities;
my $path;
$cities = get_rand_num(10) + 1;
$path = get_rand_num(10) + 1;
printf "%s %s\n", $cities, $path;
foreach (1..$path)
{
my $a = get_rand_num($cities) + 1;
my $b = get_rand_num($cities) + 1;
if ($b == $a)
{
$b = ($b + 1) % $cities + 1;
}
printf "%s %s\n", $a, $b;
}
}
}
# 这个函数是产生随机数的函数,可以在此基础上生成自己需要的数据
# 传入随机数的范围即可
sub get_rand_num
{
my $range = $_[0];
my $nb = int(rand($seed));
$nb = $nb % $range;
}
阅读(1885) | 评论(0) | 转发(0) |