Jump to content

racecar

Members
  • Posts

    1
  • Joined

  • Last visited

Everything posted by racecar

  1. Hi, I wrote a script that will generate random unique numbers that will store in a text file.When I run it over and over, It only generate 90% of unique numbers. What happen to the 10%? Can you please explain. Thank you very much. #!/usr/bin/perlsub mains {my $sov=random();my $red=readFile("lognum");chomp($red, $sov); if($red!~/^($sov)/gm){ writeFile($sov); return 1; } else { return 0; }}sub random{ my $num=int(rand()*1000); return $num;}sub readFile{ my $infile=shift; my $lines; # Provide local separator local($/, *FILE); $/=undef; open(FILE, $infile) || die "Cannot open file $infile"; $lines=<FILE>; close(FILE); return $lines;}sub writeFile{ my $outfile=shift; my $lFile="lognum"; open(OUT,">>$lFile") || die "Cannot open file $lFile"; print OUT $outfile."\n"; close(OUT);}while(1){ mains(); }
×
×
  • Create New...