Re: Object Generation - Tables vs Fractions




Nice comparison of successive fraction tables and percentage tables, but you're missing what is, IMO, a better option than either: Oddment tables.

Also, you're missing an important fact about the interaction of
your random number generator with successive fraction tables;
briefly, if your random number sequences display characteristic
orders or intra-number dependencies, you're going to wind up
with probabilities that are *NOT* in fact what your code would
imply.

Here's how oddment tables work;  You have a table with all your
stuff in it, like a percentage table.  However, instead of
assigning everything a percentage, you assign everything an
oddment - some integer greater than zero.  And every time you
add something to the table (or when you index it, if it's a
static table) you add its oddment to the total.  Now whenever
you want to generate something, you generate a random number
ranging from 0 to the total number of oddments in the table,
giving each oddment an equal probability of being rolled.

Indexing is mildly important; you don't really want to do a
linear search.  But in a pinch, you can get away with just
sorting common items to the front and optimizing the common
cases.

The beauty of an oddment table is that you can still have items
with different classes have different rarities.  You just make
their oddment the product of a constant by-class and a constant
for their own rarity.  F'r example,

#define ARMOR_PROB 33
#define WAND_PROB 20
#define ARTIFACT_PROB 1

addtotable(gentable, @wand, (WAND_PROB * wand.rarity));
addtotable(gentable, @armor, (ARMOR_PROB * armor.rarity));

etc...

gives you an overall factor for wand probability that you
can adjust relative to armor probability, changing the entire
table at once just as for a successive fraction table.

The probability calculation for any given item is
straightforward, it's resistant to bias by the RNG, and
as with any table, given some indexing it's a constant time
lookup.

Other advantages include maintainability, in that when you
add an item, it's automatic that the probability of all other
items is decreased proportionally; you don't have to "carve
out a space" for it.

					Bear



.



Relevant Pages

  • Re: backup archive format saved to disk
    ... Speaking pedantically, if the probability of error is greater than 50%, you can complement every bit and gte a probability less than 50%. ... reasons that "missing" bits are easier to correct. ... has a mis-designed channel. ...
    (Debian-User)
  • Re: Mankinds stupidest invention: The only 3 attempts rule.
    ... preceeding. ... Yeah, but like, Infinitesimally! ... My chance of missing it three times in a row = .001; this probability is the same as the probability of the criminal getting in right on any particular try. ... That means that if it's equally likely, at the beginning, to be me or a criminal, it only takes missing *four* times before the odds tilt. ...
    (rec.gambling.poker)
  • Re: Probability And Random Numbers Again
    ... > Lets say there are three containers, ... Note that this is effectively the same as picking one of the four balls ... balls we picked in the first procedure, what is the probability that 1, ... missing, or 4 is missing. ...
    (sci.math)
  • Re: Pot Odds Question
    ... The probability of missing on both the turn and the river = ... Convert to odds notation by dividing the chance of losing by the chance ...
    (rec.gambling.poker)