Game Development Reference
In-Depth Information
unsigned short Pinch = 0, // extra die to narrow bulge
SKEW_TYPE SkewDirection = SKEW_NONE, // side tail extends to
unsigned short SkewFactor = 0); // extra die to skew curve )
Rather than manually calculating the number of dice needed, this function al-
lows us to pass in a lower and upper bound for our range. This feature will also shift
the curve to a final location for us. For example, setting the boundaries to -10 and
10, respectively, would generate a range from 0 to 21 and then shift it down by 10.
When the range requested is not an exact multiple of the number of dice, the
function adds an extra die roll for the remainder. For example, 3d11 (0-indexed)
generates the range 0 to 30. If we wanted the range to be 0 to 32, the die roller would
use 3d11 and add the result of an extra d3 (0 to 2). We could have also dealt with
this by rolling 2d12 and a single d11, which yield the ranges of 0 to 22 and 0 to 10,
respectively. Adding them together results in the range 0 to 32. Please note that this
is not the method that is on the Web site at http://www.courseptr.com/downloads.
The pinch parameter changes how narrow the standard deviation will be. This
parameter actually adds additional dice to the minimum of three. Therefore, pinch
= 2 would divide the range up in five dice rather than three. As we saw before, this
raises the center of the curve and flattens the tails.
The last two parameters, SkewDirection and SkewFactor , are the same as we
encountered before.
We could call this function similarly to these examples:
RollTotal = RandomFromNormalDist( 0, 10 );
The above line returns a random number from a symmetrical normal distrib-
ution with a range from 0 to 10.
RollTotal = RandomFromNormalDist( -50, 50, 0, SKEW_NONE, 0 );
This call returns a random number from a symmetrical normal distribution
with a range from -50 to 50.
RollTotal = RandomFromNormalDist( 20, 100 , 2, SKEW_LEFT, 2 );
The above function returns a random number from a normal distribution with
a range of 81, skewed to the left (the bulge is on the right). The bulk of the popula-
tion will also be in a relatively narrow range due to the “pinch factor� of 2 in the
third parameter.
Search WWH ::




Custom Search