sub randomArray() {
my $ra_array = shift;
for ( my $i = 0 ; $i < @$ra_array ; $i++ ) {
my $index = int( rand(@$ra_array) );
@$ra_array[ $i, $index ] = @$ra_array[ $index, $i ];
}
}
my $ra_array = shift;
for ( my $i = 0 ; $i < @$ra_array ; $i++ ) {
my $index = int( rand(@$ra_array) );
@$ra_array[ $i, $index ] = @$ra_array[ $index, $i ];
}
}
Ref:
for (int i=LENGTH; i>=0; i--) { int index = rand() % i; int tmp = array[i]; array[i] = array[index]; array[index] = tmp; }
No comments:
Post a Comment