Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package {
- import flash.display.Sprite;
- import flash.net.FileReference;
- /**
- * ...
- * @author DoctorSTaL
- */
- public class TestClass extends Sprite{
- public function TestClass() {
- super();
- var max:int = 10;
- var resArr:Vector.<int> = new Vector.<int>(max);
- var r:int;
- var i:int = 10000;
- while(i--){
- r=excludedRand(-1,1,5,7,3);
- resArr[r]++;
- }
- i = max;
- while (i--) {
- trace(i+" : "+resArr[i]);
- }
- }
- private function excludedRand(max:uint, ...excludes):uint {
- if (max <= excludes.length) throw(new ArgumentError("To many excludes."));
- if (excludes.sort(Array.NUMERIC|Array.UNIQUESORT) == 0) throw(new ArgumentError("You must use unique exclusions due to use excludedRand."));
- if (excludes[excludes.length - 1] >= max) throw(new ArgumentError("All exclusions shoud be less than max value."));
- var len:uint = max - excludes.length;
- var res:uint = uint(Math.random() * len);
- for (var i:int = 0; i < excludes.length; i++) {
- if (res >= excludes[i]) res++; else break;
- }
- return res;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement