Today I had this little problem. I needed to generate a random number from 1 to 30 and the result had to except a specific number (as in this example, any number from 1 to 30 except the number 7 )
The code is done now, it’s working as it should and I posted it in case someone else needs this same code.

var randomNumber:Number;
var minNumber:Number = 1;
var maxNumber:Number = 30;
 
function generateRandomNumber():void{
	randomNumber = Math.round(Math.random() * (maxNumber - minNumber)) + minNumber;
	if(randomNumber == 7){
		generateRandomNumber();
	}
	trace(randomNumber)
}
generateRandomNumber();

By the way, the code here is ActionScript 3 but if you remove “:void” you can use it in ActionScript 2 too 😉