#!/usr/bin/ #program to generate 6 Million unique codes, Oct 15, 2011. open(MYOUTFILE, ">codesSixMil.txt"); #open for write, overwrite (>) $count = 0; #keep track of how many codes generated $count1 = 0; #keep track of how many codes duplicated $desiredQuantity = 6000001; @arrayOfResults =(); sub generate_random_string { my $stringsize = shift; my @alphanumeric = ('a'..'z', 3,4,6,7,9); my $randstring = join '', (map { $alphanumeric[rand@alphanumeric] } @alphanumeric)[0 .. $stringsize]; return $randstring; } for ($i=0;$i<$desiredQuantity;$i++) { $returnvalue = generate_random_string(10); push(@arrayOfResults, $returnvalue); $count++; } #remove any potential duplicates @unique = grep { ++$count{$_} < 2 } @arrayOfResults; #loop through array to output each code on its own line #with a carriage return as required. for ($i=0;$i<$desiredQuantity;$i++) { print @unique[$i], "\n"; print MYOUTFILE @unique[$i], "\r\n"; $count1++; } #do some rudimentary checking and output result. print "\n---Code generation report--- \n\n"; print "First array: $count \n"; print " Unique array: $count1 \n\n"; print "---There are ", $count-$count1, " code duplicates in this listing of ", $desiredQuantity, " ---\n\n\n"; #*** Close the file *** close(MYOUTFILE);