PHP gevorderde |
|
Ik vond deze code op http://www.adob...l#playgame
/**
* fisher_yates_shuffle as adapted from the Perl Cookbook,
* by Christiansen and Torkington, Published by O'Reilly
* pass this array a reference to a function. For example:
* array = new Array('hi', 'bye', 'hello', 'goodbye');
* fisher_yates_shuffle(array);
* and the function will pseudo randomize the elements of the
* array in place.
**/
function fisher_yates_shuffle(ar){
var i, j
var temp
for (i = ar.length – 1; i > 0; i––){
j = Math.floor(Math.random() * (i + 1))
if (i == j) continue
temp = ar[i];
ar[i] = ar[j];
ar[j] = temp;
}
}
/** * fisher_yates_shuffle as adapted from the Perl Cookbook, * by Christiansen and Torkington, Published by O'Reilly * pass this array a reference to a function. For example: * array = new Array('hi', 'bye', 'hello', 'goodbye'); * fisher_yates_shuffle(array); * and the function will pseudo randomize the elements of the * array in place. **/ function fisher_yates_shuffle(ar){ var i, j var temp for (i = ar.length – 1; i > 0; i––){ j = Math.floor(Math.random() * (i + 1)) if (i == j) continue temp = ar[i]; ar[i] = ar[j]; ar[j] = temp; } }
Hopelijk ben je er iets mee |