# srand(); # Generates collisions (no true random codes, also tried at the beginning of the code (not in the sub) # srand(time); # Generates collisions (no true random codes) sub GenCode { my $args = { AvailableChars => "ACDEFHIJKLMNPQRTUVWXYZ234679", CodeLength => 8, @_, }; # srand(); # Generates collisions (no true random codes, also tried at the beginning of the code (not in the sub) # srand(time); # Generates collisions (no true random codes) srand (time ^ $$ ^ unpack "%L*", `ps axww | gzip`); #seems to work, but is slow. my $rndcode = ''; my @AvailableCharsA = split "", $args->{AvailableChars}; for (my $j=0;$j<$args->{CodeLength};$j++) { $rndcode .= $AvailableCharsA[int(rand(@AvailableCharsA-1))]; } return $rndcode; }