News:

Forum changes: Editing of posts has been turned off until further notice.

Main Menu

Exploding dice: Help with calculating averages

Started by jpegbert, January 27, 2004, 04:36:20 PM

Previous topic - Next topic

jpegbert

My method for mapping 0 to 1 to a die roll was the following:

multiply the randomly generated number by 10^X where X = the number of digits on the die size (so for d4, d6 and d8, X=1 ; for d10 and d12 X=2).  Then I integer divide the result by 1 to truncate the remaining decimal and add 1 to the result.  Then I test to see if the resulting integer value is less than or equal to N, where N is the number of sides on the die.  Can you see anything inherently wrong with this method that might give skewed results?  My programming skills were always half-baked at best.

I'll try the histogram tomorrow.  My results for the d10 and the d12 make me particularly suspicious of my results.  Thanks for all of the time spent, Harlequin.

Harlequin

Hmm.  Certainly I can suggest a better method.  Throwing away all but the lowest 10% of the random number range, then looking for a truly random distribution within that bloc, does strike me as dubious.  If there are any flaws in the randomizer, you'd be almost guaranteed to find them. :)

Try this, very simple, procedure rather than wasting your time on histograms:

A) Multiply random result by N, the die size.
B) Add 0.5 to the result.
C) Round off to the nearest integer.

If the program is handling floats properly and the random range is the normal one (includes zero, does not include one, does include 0.9999), then this should work.

You could also use
A) Multiply by N
B) Round up, to next highest integer
C) If zero, value becomes N

...but I find the first method to be simpler to code, in most cases.  Darn that includes-zero random number standard.  (Interesting to envision a d8 with that physical property... one in a million or so rolls, what would have been an eight becomes a zero.  Puzzled gamer inspects die, finds the other seven sides correct.  Rolls it again, the eight is back, for a million or so more rolls.)

Try that, and see if your results come closer to the algebraic solution.

- Eric

PS: No problem.  My inner math geek likes to play.  You can pay me back by making Ken Burnside happy and convincing someone to buy Attack Vector.  I get no money, but happy Ken is fun to watch and I'd consider myself well thanked.

cthulahoops

Hi,

I thought it might be helpful to see if I can generate the algebraic results numerically.  I can.

explode.c produces the appropriate results.

Adam.

Jack Aidley

With most random number generators the high bits give a more random result than the low bits. The rand function in most languages is pretty poor anyway, so it will tend to produce bad results for stuff like this.

Harelquin's method above is the best to use if you must.
- Jack Aidley, Great Ork Gods, Iron Game Chef (Fantasy): Chanter

Jack Aidley

Thinking about it, I think calculating the average of an exploding die is going to be singular useless. More useful is working out how likely you are to hit certain target numbers.

It turns out to pretty easy to figure your odds of hitting a given target number n:

Let x be the number sides on your dice.
Let d be the interger value of n/x (i.e 5 for n = 33 and x = 6)
Let r be the remainder of the above sum.

( ^ here means to the power of)

Then:

if r = 0 p(n) = 1/x^d
if r != 0 p(n) = (x - r + 1)/( x^(d+1) )

Hope those equasions aren't too unclear.
- Jack Aidley, Great Ork Gods, Iron Game Chef (Fantasy): Chanter