Re: Dice Function

From: Mike Stilson (mike@velgarian.sytes.net)
Date: 07/07/02


On Sun, Jul 07, 2002 at 04:56:39AM -0700, Mythran wrote:
>> > Why was the dice function written as it is?
>> Because it actually simulates the rolling of a number of dice.  Your loop
>> only chooses a random number between low and high, and thus changes the
>> probabilities.
>>
>> The probability graph of 2-12 is different for "2d12" vs merely "2-12".
>>
>> And right away, that's a disadvantage.
>>
>
>Take a closer look at my post.  You will see that it is not a disadvantage
>at all....

Yes it is.  It doesn't simulate real dice.

>2d12 using the my dice() function has the same probability....it will not
>return just 2-12.

No, it returns a random number from 2 - 24.  But that's not how dice
work.  Dice have certain probabilities.  Unless your PRNG is whacked,
it's not gonna give the same results with repetition like dice.

>In my dice function, dice(2, 12) will return a min of 2 and a max of
>24....this is the same results that the stock dice function would return.

No it isn't.  At least not in the long run.
>
>Notice the return statement:
>
>return (number(num, num * size));

And to show it without the statistical analysis (nicely explained btw)
by Mythran, here's a side-by side comparison using both methods (the
original dice code and your flat random number generation) using 100000
iterations rolling 2d6.  It's pretty obvious that the dice function is
giving the same natural bell curve that sitting there rolling
(non-loaded) dice will give while your idea gives a very flat dispersal.
(2d12, 30d20, etc will still give the same curve, I just used 2d6 to
save space, just make sure to do enough loops to get an accurate sample)

$ ./dice 100000

Results:     dice    odds       number   odds
 2:          2744   36.4:1       9148   10.9:1
 3:          5630   17.8:1       9192   10.9:1
 4:          8263   12.1:1       9142   10.9:1
 5:         11047    9.1:1       8913   11.2:1
 6:         13836    7.2:1       9029   11.1:1
 7:         16696    6.0:1       9202   10.9:1
 8:         13647    7.3:1       8929   11.2:1
 9:         11269    8.9:1       9058   11.0:1
10:          8558   11.7:1       9112   11.0:1
11:          5511   18.1:1       9168   10.9:1
12:          2799   35.7:1       9107   11.0:1
dice variance: 21531608.000  standard deviation: 4640.216
number variance: 9785.891  standard deviation: 98.924

just in case, that means, on average, you'd roll a 2 once every 36.4
rolls, but you'd roll a 7 once every 6.

run them thru gnuplot to see it graphically.  something like
plot 'plot.dat' using 1:2 smooth csplines title "Dice"
replot 'plot.dat' using 1:4 smooth csplines title "Number"
(bezier gives a nicer bell curve but distorts the data too much)
and you'll see the difference even easier.

-me

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   | Newbie List:  http://groups.yahoo.com/group/circle-newbies/   |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 06/25/03 PDT