Game Development Reference
In-Depth Information
Second, if we haven't determined a range artificially (for example, stating that
we are only concerned with x values between 5 and 15), we can easily identify the
range of the distribution as the areas where y > 0. Through some painless algebraic
yoga we can solve any equation for the point y = 0 to determine the exact point at
which this occurs along the x -axis.
Some variations to linear equations merit mention. Not all lines will intercept
the x -axis in the range that we are concerned with. In Figure 11.17A, for example,
the probability increases over the range between x min and x max . At no time, however,
is that probability 0.
FIGURE 11.17 (A) A linear distribution that does not reach 0 within the range.
(B) A linear distribution that reaches 0 within the range. Values below 0
must be clamped to 0. (C) A linear distribution that extends beyond a defined
maximum must be clamped to the maximum.
If we have established a range for the possible events (e.g., x min to x max ), we may
encounter a situation where the probability line proceeds below 0 (Figure 11.17B).
We need to be careful to trap our code to avoid the possibility of negative probabil-
ity. In those circumstances, overriding the formula to set y to 0 is a simple solution.
Similarly, if we set a maximum value for y , we need to be aware of another po-
tential problem. In the graph shown in Figure 11.17C, we see that the line proceeds
above the maximum value that we have set for y . In these cases, we must be careful
to cap the value returned by our formula to y max .
The bottom line on linear distributions is that they are a simple yet elegant so-
lution to crafting increasing or decreasing probabilities. It certainly makes for a nice
change of pace from uniform distributions but without time-consuming clutter. As
mentioned above, we will soon show a method for selecting random numbers out
of this distribution.
Search WWH ::




Custom Search