in reply to Random data generation.

my @set = split //, "ABCDEF"; my $len = 12; my $max_reps = 2; say gen(\@set, $len, $max_reps) for (1..20); sub gen { my ($set, $len, $max_reps) = @_; my $out = ''; my $last_ix = -1; my $reps = 0; for (1..$len) { my $ix; if ($reps >= $max_reps) { $ix = int rand(@$set - 1); $ix++ if $ix >= $last_ix; } else { $ix = int rand(@$set); } if ($ix == $last_ix) { $reps++; } else { $last_ix = $ix; $reps = 1; } $out .= $set->[$ix]; } $out; }

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

    Yep. That's pretty much exactly what I came up with for my first attempt. Though I think I needed one more flag.