Game Development Reference
In-Depth Information
for ( unsigned short i = 1; i <= NumDie; i++ ) {
TotalRoll += SingleDie( NumSides, ZeroBased );
} // end for
return TotalRoll;
}
The call to the function MultipleDie() takes an additional parameter for the
number of dice we want to roll. In this way, we can get our random 3d11 roll
through a single function call:
unsigned short RollResult = MultipleDie( 3, 11 );
Changing the Shape
If we change our number generator from 3d11 to 5d7, it still generates numbers
from 0 to 30. The curve exhibits some different characteristics, however (Figure
11.9). The range of the distribution is still 0 to 30, but the center of the chart is taller
and narrower than the one in Figure 11.8. This is because the standard deviation of
this distribution is only 3.4, rather than the wider 5.48 of the prior curve. The re-
sult of this is that the 68% of the population that is in the first standard deviation is
condensed into a smaller range— from 11 to 19. In plain English, this means we can
more reliably expect numbers nearer the mean of 15.
FIGURE 11.9 The random numbers generated using 5d7 create a taller, more
condensed curve. The standard deviation is only 3.4. Therefore, only the
selections from 11 to 19 (in black) are in the first standard deviation.
Search WWH ::




Custom Search