The algorithm was developed on one of the hot nights when you couldn't sleep, either. The Perl has taken me 2 days to write with all the other distractions life affords. I learned some useful stuff writing it (thanks, Tye, for helping me in CB), so I'm putting it up even though you have your solution!use strict; use warnings; my $nRepeats = 2; my @sSet = qw (a b c d e f); my $nLength = 12; my %sSets; for my $nKey (0..((@sSet) ** $nRepeats - 1)) { my $sKey = ""; for (1..$nRepeats) { $sKey .= $sSet[($nKey / (($#sSet + 1) ** ($_ - 1))) % ($#sSet ++ 1)]; } $sSets{$sKey} = [@sSet]; } for (0..$#sSet) { splice(@{$sSets{$sSet[$_] x $nRepeats}}, $_, 1); } my $sString; my @sChr; for (1..$nRepeats) { my $sRnd = $sSet[int(rand(@sSet))]; $sString .= $sRnd; push(@sChr, $sRnd); } for ($nRepeats + 1 .. $nLength) { my $sKey; for (@sChr) { $sKey .= $_; } my $sRnd = @{$sSets{$sKey}}[int(rand(@{$sSets{$sKey}}))]; $sString .= $sRnd; push(@sChr, $sRnd); shift(@sChr); } print "$sString \n";
In reply to Re: Random data generation.
by davies
in thread Random data generation.
by BrowserUk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |