in reply to Re: Random data generation.
in thread Random data generation.

Your approach could be made to work by simply checking the last two characters:

my @set = qw( A B C D E F ); my $len = 12; my $result = ''; while (length($result) < $len) { my $char = $set[ rand @set ]; next if substr($result, -2) eq $char x 2; $result .= $char; } print $result;

Also, there's no need to use an extra variable (like $last_char), as $result already stores all the previous characters.

Replies are listed 'Best First'.
Re^3: Random data generation.
by bluescreen (Friar) on Jun 26, 2010 at 18:07 UTC

    Absolutely it was a quick-&-dirty script, probably to much :D, I knew that instead of $last_char I could have used substr(), but premature optimization made me do that.

    Anyway this sort of social coding brought an interesting result