Silly idea but, as you say, the decision is out of you hands :-(

Set up the four sets already shuffled then make an array of references to them. Then create another array with a guaranteed one from each set (0 .. 3) then a random selection of four more from any set. Then shuffle the order. Finally, build the password by concatenating random letters from the sets in the already shuffled order.

knoppix@Microknoppix:~$ perl -MList::Util=shuffle -Mstrict -wE ' my @lc = shuffle q{a} .. q{z}; my @uc = shuffle q{A} .. q{Z}; my @dig = shuffle q{0} .. q{9}; my @oth = shuffle qw{ ! " £ $ % ^ & * _ - + = @ ~ }; my @all = \ ( @lc, @uc, @dig, @oth ); my @order = ( 0 .. 3 ); push @order, int rand 4 for 1 .. 4; @order = shuffle @order; my $passwd = q{}; $passwd .= $all[ $_ ]->[ rand @{ $all[ $_ ] } ] for @order; say $passwd;' E5yR=$%£ knoppix@Microknoppix:~$

Runs of this have produced &D0%@nn%, F9@F=Rc1, S~j@3WgG, 633P£m!T and o8S4pl!! so, as long as there is no stipulation barring repeated characters, this seems to work.

I hope this is useful.

Update: If repeated characters are not wanted then you can use splice to remove the chosen character from the array so it can't be re-used.

... $passwd .= splice @{ $all[ $_ ] }, rand @{ $all[ $_ ] }, 1 for @order; ...

Cheers,

JohnGG


In reply to Re: Handling elements of an array of array references, where the function calls for an array? by johngg
in thread Handling elements of an array of array references, where the function calls for an array? by desertrat

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.