Game Development Reference
In-Depth Information
Converting Functions to Distributions
To convert a larger dataset such as the results of a function, we need to automate the
process of adding buckets. For this example, we will use an uneven probability dis-
tribution applied to 10 items. The probabilities of the 10 items follow the formula:
For a visual reference, the graph of the number of occurrences looks like the
one in Figure 12.3.
FIGURE 12.3
The histogram showing the number of occurrences of each selection
is based on the formula y = -1( x - 100) + 12.
The first thing we do is create the struct that will act as our data bucket.
struct sBUCKET {
USHORT Size; // The size of this bucket = probability
USHORT Edge; // The edge of this bucket based on its position
USHORT Result; // The result we are generating = x
};
As with our dentist example, each record holds the size of the bucket, its edge
location, and what the result will be. We've changed the terminology slightly here.
Search WWH ::




Custom Search