That's a good idea. Here is a stab at it using String::Random. The sub generates a string of given length of 0,1,2 and then converts this to character codes that String::Random understands. The sub ensures that no three values in a row are the same.

use String::Random; my $length = 10; my $Random = new String::Random; # add new pattern char for upper and lower case $Random->{'A'} = [ 'A'..'Z', 'a'..'z' ]; my $pattern = generate_pattern($length); my $password = $Random->randpattern($pattern);; say $password; sub generate_pattern { my $length = shift; # populate first two values my @chars = ( int(rand(3)), int(rand(3)) ); for my $i (2..$length-1) { # check if previous two values match if ($chars[$i - 1] == $chars[$i - 2]) { my @other_values = grep( !($_ == $chars[$i - 1]), (0..2)); # get random other value. ie if last two values were 1, pick +0 or 2 $chars[$i] = $other_values[ int(rand(2)) ]; } else { $chars[$i] = int(rand(3)); } } my $pattern = join '', @chars; # convert random string of 0,1,2 to A,n,! $pattern =~ tr/012/An!/; return $pattern; }

Edit: It's a little ugly, but this is quite a bit faster than the route I took in my other code sample above.


In reply to Re^2: Removing similar characters by Kc12349
in thread Removing similar characters by rspishock

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.