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
In reply to Randomising the order of an array by g0n
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |