Array Shuffle
Uses a ds_list to shuffle an array
Script array_shuffle
///array_shuffle(array,size,zero_based)
//array: the array to shuffle. Indices must start at zero or one.
//size: the size of the array (how many elements are in the array)
//zero_based: true if indices start at 0, false if they start at 1
//set up some values for us to use
var list,i,ret,array,top,bottom,zero_based;
array = argument0;
top = argument1;
zero_based = argument2;
bottom = 0;
if (!zero_based) {
top +=1;
bottom += 1;
}
//create a list, fill it, and shuffle it
list = ds_list_create();
for (i=bottom; i<top; i+=1) {
ds_list_add(list,array[i]);
}
ds_list_shuffle(list);
//put the list back into a new array
for (i=bottom; i<top; i+=1) {
ret[i] = ds_list_find_value(list,i);
}
//clean up the list when we're done
ds_list_destroy(list);
//return the new, shuffled array
return ret;