in reply to Random data generation.

$ perl -le' use List::Util qw/ shuffle /; my @chars = qw/ A B C D E F /; my $length = 12; my $repeats = 2; my @set = shuffle( ( @chars ) x $repeats ); die "Error!\n" if @set < $length; print join "", @set[ 0 .. $length - 1 ]; ' FCBECFADABED

Replies are listed 'Best First'.
Re^2: Random data generation.
by BrowserUk (Patriarch) on Jun 26, 2010 at 13:20 UTC

    That's the one. For the life of me I don't see how it works yet, but it does. Many thanks.

      As there are only two of each character in the set which is shuffled ((@chars) x 2), there can of course also only occur two in a row at maximum.

      OTOH, this technique doesn't allow more than two of any character in the result (like AACBAFFDCAEC), so it might introduce an unwanted bias... (you didn't explicitly say whether this is desired or not, and it cannot be inferred from your valid samples).

        You're right. No, it isn't the one. It won't do at all.

      It's not random. Not even close. For example, you'll never have three of the same character anywhere in the string.

      I don't know if it matters, but it only works if $len <= @set*2