0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

配列をランダムにシャッフルする関数

Posted at

shuffleList | CreateJS

配列をランダムにシャッフルする関数

////////////////////////////////////////
// 連番配列生成
////////////////////////////////////////
function createList(first, length) {
	var n;
	var list = [];
	for (n = first; n < first+length; n++) {
		list.push(n);
	}
	return list;
}

////////////////////////////////////////
// ランダム配列処理
////////////////////////////////////////
function shuffleList(list) {
	var n = list.length;
	var _list = list.concat();
	while (n--) {
		var i = Math.floor(Math.random()*(n + 1));
		var t = _list[n];
		_list[n] = _list[i];
		_list[i] = t;
	}
	return _list;
}
0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?