in reply to Random data generation.
ikegami's is a general solution for all cases, but would it be sufficient in non-extreme cases (i.e., not trying to generate 100-character strings from just two different characters and with no more than two sequential repeats) to just generate bunches of strings and throw away all that are non-compliant?
>perl -wMstrict -le "use List::Util qw(shuffle); my @set = qw(a b c d e f); my $len = 12; my $needed = shift; my @out; while (@out < $needed) { my $str = join '', shuffle((@set) x $len); push @out, grep !m{ (.)\1\1 }xms, $str =~ m{ .{$len} }xmsg; } @out = @out[-$needed .. -1]; m{ (.)\1\1 }xms and die qq{3+ same: '$_'} for @out; printf qq{%3d: '$out[$_]' \n}, 1+$_ for 0 .. $#out; " 5 1: 'becaecdbbedc' 2: 'afccbecefdca' 3: 'fbffecacfeaa' 4: 'ddbacddfafca' 5: 'fbebdabadedc'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Random data generation.
by ikegami (Patriarch) on Jun 26, 2010 at 15:33 UTC | |
by AnomalousMonk (Archbishop) on Jun 26, 2010 at 20:06 UTC | |
by ikegami (Patriarch) on Jun 27, 2010 at 06:16 UTC | |
|
Re^2: Random data generation.
by BrowserUk (Patriarch) on Jun 28, 2010 at 12:12 UTC |