http://www.perlmonks.org?node_id=1015214


in reply to Password (pseudo)casual

Just a variation on this theme using the buildin features:

#!/usr/bin/perl + use strict; use warnings; my ( @l, @u, @n, @s, @p, $i, $j ); open( URANDOM, "</dev/urandom" ) || die $!; read( URANDOM, $_, 4 ); close URANDOM; srand( unpack( "L", $_ ) ); @l = ( "a" .. "z" ); @u = ( "A" .. "Z" ); # @n = ( 0 .. 9 ); + # @s = ( + # '#', ',', ' ', + # qw( ! " $ % & ' ( ) * + - . / : ; < = > ? @ [ \ ] ^ _ ` { | } ~ + ) # ); + push( @p, splice( @l, int( rand(@l) ), 1 ) ) for ( 1 .. 10 ); push( @p, splice( @u, int( rand(@u) ), 1 ) ) for ( 1 .. 10 ); # push( @p, splice( @l, int( rand(@l) ), 1 ) ) for ( 1 .. 3 ); + # push( @p, splice( @u, int( rand(@u) ), 1 ) ) for ( 1 .. 3 ); + # push( @p, splice( @n, int( rand(@n) ), 1 ) ) for ( 1 .. 2 ); + # push( @p, splice( @s, int( rand(@s) ), 1 ) ) for ( 1 .. 2 ); + for ( $i = @p ; --$i ; ) { $j = int( rand( $i + 1 ) ); next if $i == $j; @p[ $i, $j ] = @p[ $j, $i ]; } print join( "", @p ) . qq(\n); __END__

Regards, Karl

«The Crux of the Biscuit is the Apostrophe»