【AS3代码】随机洗牌阵列
package
{
import flash.display.Sprite;
import org.osmf.net.dynamicstreaming.INetStreamMetrics;
public class Main extends Sprite
{
var startDeck:Array = new Array();
var shuffledDeck:Array = new Array();
public function Main():void
{
init();
}
private function init():void
{
for(var cardNum:int = 0; cardNum < 52; cardNum++)
{
startDeck.push(cardNum);
}
trace("原始数组:" + startDeck);
//随机排序数组
while (startDeck.length > 0)
{
var r:int = Math.floor(Math.random() * startDeck.length);
//将随机出来的数据放入到新数组中
shuffledDeck.push(startDeck[r]);
//将该数据从原始数组中删掉
startDeck.splice(r,1);
}
trace("随机排序后数组:" + shuffledDeck);
}
}
}
{
import flash.display.Sprite;
import org.osmf.net.dynamicstreaming.INetStreamMetrics;
public class Main extends Sprite
{
var startDeck:Array = new Array();
var shuffledDeck:Array = new Array();
public function Main():void
{
init();
}
private function init():void
{
for(var cardNum:int = 0; cardNum < 52; cardNum++)
{
startDeck.push(cardNum);
}
trace("原始数组:" + startDeck);
//随机排序数组
while (startDeck.length > 0)
{
var r:int = Math.floor(Math.random() * startDeck.length);
//将随机出来的数据放入到新数组中
shuffledDeck.push(startDeck[r]);
//将该数据从原始数组中删掉
startDeck.splice(r,1);
}
trace("随机排序后数组:" + shuffledDeck);
}
}
}