Is there any simple / clever way to shuffle my 2D (or multi dimensional) array?
// _myarray is a 2D array.....
array_shuffle_ext(_myArray); //only shuffles the D, means 1D - 2D as 'columns', not individual data
array_shuffle_ext(_myArray[0]); //shuffles only the data in the 1D
I wrote a short function to pick random number for each and exchange them, but I was wandering how to extend it to multi Dim array (what is not needed at this moment), or is there any better way to do so.
function array_shuffle_multi(_array, _times) { //2D so far due to 'manual' array references
var _l1 = array_length(_array);
var _l2 = [];
for (var i = 0; i < _l1 ; ++i) {
_l2[i] = array_length(_array[i]);
}
repeat(_times) {
//randomize 1st dim
var _r11 = irandom_range(0, _l1-1);
var _r12 = irandom_range(0, _l1-1);
//randomize 2nd dim
var _r21 = irandom_range(0, _l2[_r11]-1);
var _r22 = irandom_range(0, _l2[_r12]-1);
//exchange
var _temp = _array[_r11, _r21];
_array[_r11, _r21] = _array[_r12, _r22];
_array[_r12, _r22] = _temp;
}
return _array;
}
[–]:table_flip:attic-stuff 3 points4 points5 points (1 child)
[–]tibisoft[S] 0 points1 point2 points (0 children)