![]() So if every item has the same weight (regardless of whether that's 1 or 1,000,000), they will have an equal chance of being generated. Weight represents how often the element will be selected, relative to other weights. That is left to an object factory, so that the generator can be used for more than one type of creation.Ī key concept to this algorithm is that of weight. Note that this generator only selects the item it does not actually create it. Otherwise, the generator subtracts the current element's weight, and goes to the next entry.Įssentially, this mimics the effect of constructing a large table, as in table-top RPGs, and then rolling on it this, however, is much cheaper computationally. At each entry, if the roll is less than the current element's weight, the generator returns the element. The generator then begins running down the second list. With the list complete, the generator picks a number between 0 and 1, and multiplies it by the total weight (we'll call this "the roll"). ![]() Every time it copies one of these elements over, it adds the weight of the element to a total. Then, it copies elements of the list of possibles who's level requirements are met by the passed level. ![]() But when different results have different probabilities, something a little more complex is called for.Ī weighted random generator works by accepting a list of possible results, each with a weight, a minimum level, and a maximum level. When each option is equally likely, this is simple enough. ![]() With their significant level of randomly-generated content, it is very helpful for a Roguelike to have a single method of managing it all. ![]()
0 Comments
Leave a Reply. |