Код:
#!/usr/bin/perl # By: Fryxar # Min number of numbers $MAXCARNUM = 2; # Min number of upper case letters $MAXCARMAY = 2; # Min number of lower case letters $MAXCARMIN = 2; # Others (numbers + upper letters + lower letters) $MAXCARALL = 2; # Total length (sum off all) $MAX = $MAXCARNUM+$MAXCARMAY+$MAXCARMIN+$MAXCARALL; $numbers = "0123456789"; $lower = "qwertyuiopasdfghjklzxcvbnm"; $upper = "QWERTYUIOPLKJHGFDSAZXCVBNM"; $all = $numbers . $lower . $upper; @password = (); $j = 0; # Generate numbers for( $i=0; $i < $MAXCARNUM; $i++ ) { srand; $rand = int(rand length $numbers); $password[$j++] = substr( $numbers, $rand, 1 ); } # Generate upper letters for( $i=0; $i < $MAXCARMAY; $i++ ) { srand; $rand = int(rand length $upper); $password[$j++] = substr( $upper, $rand, 1 ); } # Generate lower letters for( $i=0; $i < $MAXCARMIN; $i++ ) { srand; $rand = int(rand length $lower); $password[$j++] = substr( $lower, $rand, 1 ); } # Generate lower letters + upper leters + numbers for( $i=0; $i < $MAXCARALL; $i++ ) { srand; $rand = int(rand length $all); $password[$j++] = substr( $all, $rand, 1 ); } # Mix the vector for( $i=0; $i < $MAXCARNUM+$MAXCARMAY+$MAXCARMIN+$MAXCARALL; $i++ ) { srand; $rand = int(rand $MAX); $swap = $password[$i]; $password[$i] = $password[$rand]; $password[$rand] = $swap; } # And finaly print it! foreach $_ (@password) { print "$_"; } print "\n";