# Random.Range is trolling

I use Random to place GameObject, but he always rollin the same Field.

How to Fix this ?

This is the Chunk with the problem:

``````		while (tempFillPerc < brushFillPerc ) {

//Sollange du innerhalb des Rahmens bist, verschiebe den Pinsel
if ((rndX >= border) && (rndX <= maxLevelSizeX-border) && (rndZ > border) && (rndZ < maxLevelSizeZ - border)){
rndX = rndX + Random.Range(-border,border);
rndZ = rndZ + Random.Range(-border,border);
}

// Wir sind am Rahmen, Richtung umkehren !
if (rndX < border) {
rndX = rndX + Random.Range(0,border);
rndZ = rndZ + Random.Range(-border,border);
}
// Wir sind am Rahmen, Richtung umkehren !
if (rndX > maxLevelSizeX - border){
rndX = rndX - Random.Range(0,border);
rndZ = rndZ + Random.Range(-border,border);
}
// Wir sind am Rahmen, Richtung umkehren !
if (rndZ < border) {
rndZ = rndZ + Random.Range(0,border);
rndX = rndX + Random.Range(-border,border);
}
// Wir sind am Rahmen, Richtung umkehren !
if (rndZ > maxLevelSizeZ - border) {
rndZ = rndZ - Random.Range(0,border);
rndX = rndX + Random.Range(-border,border);
}

if ((rndX >= border) && (rndX <= maxLevelSizeX-border) && (rndZ >= border) && (rndZ <= maxLevelSizeZ-border))
inselgenerierung(rndX, rndZ);

tempFillPerc=calcFillPercent();
}
``````

Sometimes, you just need to take a deep breath, select everything between the opening and closing brackets of your function, and hit the delete key.

Then open a text editor and write down, in plain German, what exactly that function is supposed to do. Then go back and give the code another try from scratch. I don’t think that script does what you think it does; and I think it is a lot longer than it needs to be.

But I don’t really know, without the context of what you posted.
If you explained what your script is supposed to do, it would be easier to help you fix it.

The one problem I see clearly is that you’re randomizing rndx and rndz only if they are in the border area. Did you forget to give them an initial random value?