1 2 3 4 5 6 7 8 9 10 11
| var cards = [];
for (var i = 1; i <= 54; i++) { cards.push(i); } //这个就是顺序保存数据的过程
for(var i = 0; i <= 54 / 2; i ++) { var id1 = parseInt(Math.random(1, 53) * 53), tmp = null; tmp = cards[id1]; cards[id1] = cards[i]; cards[i] = tmp; }</p>
//chrome 执行结果
> cards
[5, 15, 9, 18, 1, 39, 11, 50, 10, 21, 54, 31, 35, 27, 13, 22, 43, 51, 2, 53, 14, 24, 48, 20, 26, 37, 33, 44, 29, 30, 12, 32, 3, 34, 19, 36, 25, 38, 6, 40, 41, 42, 17, 28, 45, 46, 47, 23, 49, 8, 4, 52, 16, 7]
|