« ボックスの中心に画像を強制的に配置 | メイン | javascriptで画像いじりメモ »
2014年09月22日
javascriptランダム化
とりあえず何も考えずにw
function shuffle(array) {
var copy = [], n = array.length, i;// While there remain elements to shuffle…
while (n) {// Pick a remaining element…
i = Math.floor(Math.random() * array.length);// If not already shuffled, move it to the new array.
if (i in array) {
copy.push(array[i]);
delete array[i];
n--;
}
}return copy;
}
投稿者 muuming : 2014年09月22日 11:16