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.
In reply to Re^2: Random data generation.
by almut
in thread Random data generation.
by BrowserUk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |