Random Number Script

Hi!

I’ve written a random number script. It works fine, except for the fact that when it has picked every number within the range, it stops.

I have it print out what it gets in the Debug.Log. Is it because of the Debug.Log that it stops after picking every possible number, or is there a better way to script this?

This occurs only in the int version of the random number when it is getting a new one every frame. I’m sure it would happen with the float version too, but the possibilities for a floating point number are endless.

var everyframe : boolean = false;
var floatnum : boolean = false;
var lowestfloat : float = 0.0;
var highestfloat : float = 0.0;
var lowestint = 0;
var highestint = 0;

function Awake(){
	if(everyframe == false){
				if(floatnum == true){
			var choice = Random.Range(lowestfloat,highestfloat);
		}
		if(floatnum == false){
			choice = Random.Range(lowestint,highestint);
		}
		Debug.Log(choice);
	}
}

function Update () {
	if(everyframe == true){
		if(floatnum == true){
			choice = Random.Range(lowestfloat,highestfloat);
		}
		[COLOR="#ff0000"]if(floatnum == false){
			choice = Random.Range(lowestint,highestint);[/COLOR]
		}
		Debug.Log(choice);
}
}

Turn off “collapse” in the console.

–Eric

Haha. Thanks, man! Worked like a charm!

lol, Eric. I think that’s the 2937492734th time I’ve seen that response out of you. :smile:

I think it serves as ample proof that “collapse” really should be off by default. I’ve said that before too. :wink:

–Eric

Yeah, I definitely agree with you there.