g0n has asked for the wisdom of the Perl Monks concerning the following question:
I have an array in the following format:
my @dataArray = (\@inputValue1,\@outputValue1,\@inputValue2,\@outputVa +lue2..)
to the tune of 1700 pairs of input/output pairs (read in from a file). Unfortunately, these data are ordered in the file, whereas I want them random. This code:
# Subroutine to jumble the data sub jumble { for (1..50) { my $endpoint = int(rand(scalar @dataArray -1)); if ($endpoint % 2){$endpoint++} my (@tempArray) = (@dataArray[$endpoint..(scalar @data +Array-1)]); push @tempArray,(@dataArray[0..$endpoint-1]); @dataArray = @tempArray; } }
does the job of randomizing them well enough, but is there a better way?
TIA.
Update: In case I haven't made it clear, \@inputValue1 and \@outputValue1 need to remain adjacent, but I'm randomising the order so that input/output pair 1 is not necessarily adjacent to input/output pair 2.
--------------------------------------------------------------
g0n, backpropagated monk
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Randomising the order of an array
by ikegami (Patriarch) on Jul 19, 2005 at 18:44 UTC | |
|
Re: Randomising the order of an array
by brian_d_foy (Abbot) on Jul 19, 2005 at 21:28 UTC | |
|
Re: Randomising the order of an array
by JediWizard (Deacon) on Jul 19, 2005 at 18:38 UTC | |
|
Re: Randomising the order of an array
by mrborisguy (Hermit) on Jul 19, 2005 at 18:40 UTC | |
by ikegami (Patriarch) on Jul 19, 2005 at 18:49 UTC | |
by Anonymous Monk on Jul 19, 2005 at 20:03 UTC | |
by ikegami (Patriarch) on Jul 19, 2005 at 20:07 UTC | |
by Anonymous Monk on Jul 19, 2005 at 20:14 UTC |