use Bytes::Random::Secure; use List::Util 'shuffle'; use constant CSPRNG => Bytes::Random::Secure->new( NonBlocking => 1 ); sub uppers { return CSPRNG->string_from( join( '', 'A'..'Z' ), shift // 2 ); } sub lowers { return CSPRNG->string_from( join( '', 'a'..'z' ), shift // 2 ); } sub mixed { return CSPRNG->string_from( join( '', 'A'..'Z', 'a'..'z', '0'..'9', '!@#$%^&*()_+{}|[]\<>?,./:;"\'' ), shift // 4 ); } sub gen_pass { my $uc = uppers(); my $lc = lowers(); my $mix = mixed(); return join( '', shuffle( split //, "$uc$lc$mix" ) ); } for ( 1 .. 10 ) { print gen_pass(), "\n"; }