/ Published in: ActionScript 3
Random generator with no repetiotion using ActionScript 3
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
var baseArray:Array; var numToGet:int = 8; function makeBaseArray(f_length:int):void { baseArray = new Array(); for (var i:int = 0; i < f_length; i++) { baseArray.push(i); } } function getRandomNoRepeat():Number { var index:int = Math.random() * baseArray.length; var value:int = baseArray.splice(index,1)[0]; return value; } makeBaseArray(16); for (var i:int = 0; i < numToGet; i++) { trace(getRandomNoRepeat()); }