Exclude a range in a random range of numbers

hello!

i need a random number between 100 and 900 but without the numbers between 400 and 600.
i cant find an answer. is it something like Random.Range(100,400) || (600,900) ?

No.

For the simple problem of excluding a range of numbers, you could just use an ad hoc solution, e.g. (untested pseudocode):

int value = Random.Range(100, 702);
if (value > 400) {
    value += 199;
}

(Not sure if I got that right, but it should be something like that. Also, you’d most likely want to use variables rather than literals for the range boundaries.)

For anything more involved than that, you’d probably want to implement a more general system that selected a number randomly from a specified set of numbers.

Note also that the integer version of Random.Range() treats the input range as the range [min, max) (that is, the ‘max’ value is excluded). In my example though, I made the assumption that you wanted the ranges [100, 400] and [600, 900] to be inclusive.

thank you for your answer.

i got now this script to load some trees and place them in a random position. it works fine.

var trees : float;	

	for (var i = 0; i < trees; i++){
	var instance : GameObject = Instantiate(Resources.Load("tree"));
	
	var xrandom = Random.Range(200, 600);
    if (xrandom > 400) {
    xrandom += 200;
	}
	instance.transform.position.x= xrandom;
	
	instance.transform.position.y=5;
	
	var zrandom = Random.Range(200, 600);
    if (zrandom > 400) {
    zrandom += 200;
    }
    instance.transform.position.z= zrandom;
}