# How To Reduce Probability

Hello,

I generate a block of boxes, where the the probability reduces with incresed heigth.

``````	if(countx<10)
{
for (countx = 0;countx < 10; countx++)
{
for(countz = 0; countz < 10; countz++)
{
for(county = 0; county <10; county++)
{
value = Mathf.Round(Random.value-(county/10));
if(value == 1)
{
Instantiate (prefab, Vector3(transform.position.x+countx * 4, transform.position.y+(county * 4), transform.position.z+countz * 4), Quaternion.identity);
}
}
}
}
}
``````

it isn’t the best method, i’m currently stuck to do a smooth decresing probability. I think i should use a proper modifer variable for the random value. But at the moment i can’t come up with one…
Any suggestions?

I would suggest if you’re JUST going for a probability curve, brush up on your mid-high level math and start playing with things like exponents, logarithms, etc.

Off the top of my head, I could give Random.Range(1, (county3+1)) and have it instantiate whenever the range is >=(county2) What this specifically would do is make the block have to pass a 2/3 chance ‘y’ times to spawn (i’e 4/9 for y = 2 layer, 6/12 for y = 3, and so on). It’s doesn’t calculate the TRUE probabilty for that explanation, but it’s good enough for something like this (my statistics are… really rusty). In short:

``````value = Random.Range(1,(county*3)+1)
if(value >= county(county*2));  //And so on.
``````

With most procedural content, unless you get REALLY lucky you’re probably not gonna be satisfied with this the first time. Play with the numbers, use this as a starting point and tweak it until you find a curve you like.