Last active
December 12, 2015 05:28
-
-
Save FrancescoMaisto/4721578 to your computer and use it in GitHub Desktop.
Returns a random integer ranging from 1 to max, excluding numberToAvoid.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package utils | |
{ | |
/** Returns a random integer ranging from 1 to max, excluding numberToAvoid. */ | |
public function pickRandomNumberExcept(numberToAvoid:uint, max:uint):uint | |
{ | |
// Create and populate a Vector to pick the numbers from, excluding numberToAvoid. | |
var numberContainer:Vector.<uint> = new Vector.<uint>(); | |
for (var i:uint = 1; i <= max; i++) | |
{ | |
if (i != numberToAvoid) | |
numberContainer.push(i); | |
} | |
var randomPick:uint = numberContainer[getRandomNumber(0, numberContainer.length - 1)]; | |
// trace("3: [pickRandomNumberExcept.as] randomPick =" + randomPick); | |
return randomPick; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment