# How to change chance of spawn based on distance?

I am trying to make a cellular automate cave but want to keep the middle empty.

How should I change the chance based on the distance from the middle?

I don't want to completely deny it just want a small enough chance to keep it almost empty.

You need to think along the lines of uneven distribution. For example squaring the random value:

if Sqr(Random) > (1 - NormalizedDistanceFromCenter) then AddMonster


will give you a nice squared distribution:

Distance | Chance
---------|------
0        | 0%
0.2      | 11%
0.4      | 23%
0.6      | 37%
0.8      | 55%
0.9      | 69%
1.0      | 100%

• I made a different approach : if ( Math.random() > 1-0.8*(Math.abs(half_distance*0.5-distance)/distance) ) { } – spepe Mar 7 '15 at 16:39