Friday 19 February 2010

shuffle an array

var total_questions:int = 10
var temp:Array = new Array()
var random_order:Array = new Array() 

for (var i:int; i < total_questions; i++) {
    temp.push(i)
}

while (temp.length > 0) {
    var r:int = Math.floor(Math.random() * temp.length)
    random_order.push(temp[r])
    temp.splice(r, 1)
}

Followers