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 |