Skip to content

Instantly share code, notes, and snippets.

@FrancescoMaisto
Last active December 12, 2015 05:28
Show Gist options
  • Save FrancescoMaisto/4721578 to your computer and use it in GitHub Desktop.
Save FrancescoMaisto/4721578 to your computer and use it in GitHub Desktop.
Returns a random integer ranging from 1 to max, excluding numberToAvoid.
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