The two of you start rattling off arcane gaming formulae

Distribution of Dice Rolls

gen_roll num_of_dice size_of_die

Source Code for gen_roll.cc

This compiles under gcc, Sun CC and Microsoft Visual C 1.5. Fairly generic C++, so it should compile most other places as well.

Here are executable versions. AnonFTP doesn't seem to work, so use your browser's "Save link as ..." options.

MS-DOS version

Sun Version

The UltraSparc version wouldn't run here on Digex's access machines, but the version I compiled here runs on the UltraSparc, go figure.

Release Notes

Algorithm

This isn't very clever, if I felt like it I suppose I could dig up my probability / statistics textbook and find the proper formulas for this, but in this case brute force works fine. Well, almost fine. combinatorial and factorial math being what it is, 6D10 is okay, 7D10 is a very noticable delay, 10D10 took 11 hours on a Pentium 90 (which is why a copy of that output is here.

Language

It requires C++, primarily because I allocate arrays that aren't sized until runtime. No actual OO code, because I didn't really need any objects. I thought about a die and throw object set, where throw is an aggregation of die objects, complete with a rand() based die::roll() function and throw::sum() but quickly realized it was overkill.

Coding Style and Documentation

Me bad. Throw away code. No document'um.

The only two tricky parts are the doubles, had to use them because the tally counter was overflowing a long, and increment().

increment() is an odometer style increment that operates on the array. Each time a digit chages, it resets all lower digits. The initial loop is to find the last digit incremented, we then increment that one, and then count down through last_ndx to do the resets.

Everything ought to be obvious.

Oh, yea. I used stdio instead of cout stream, I still have to think to use cout, my fingers can type a printf format string without actually making a brain access.