November 30, 200421 yr For my first recursive custom function, I created a simple dice-rolling function. It returns the sum of N number of S-sided dice, as might be used with role playing games, etc. Dice(N,S) If( N > 0; Round(Random * S + .5; 0) + Dice(N - 1; S); N ) RECURSION... Recursion... Recursion... ...is kewl! is kewl! IS KEWL!
November 30, 200421 yr Cool, I tried your function out for a spin on my Dual G5 and have some mostly useless results to report. It takes about 1 minute to roll two six sided dice 45,000 times using a looping script which creates a record and stores the roll result in a calc field. This compares to 90,000 records created in the same amount of time w/o rolling the dice. Here are the statistics after 45,000 rolls 2 2.720% 12 2.824% 11 5.444% 3 5.627% 4 8.306% 10 8.584% 5 10.712% 9 11.327% 6 13.887% 8 13.921% 7 16.647% Here are the stats after 3 million rolls 2 2.784% 12 2.785% 3 5.525% 11 5.547% 4 8.315% 10 8.350% 9 11.144% 5 11.153% 8 13.855% 6 13.872% 7 16.670% I guess all this proves is that the random function doesn't appear to skew to the high or low end (and that I have too much time on my hands.)
December 2, 200421 yr Author Thanks for doing my testing for me, I had only run a few thousand. Looks like the distribution is pretty much right on the money.
December 3, 200421 yr Here's a little utility to calculate the statistics of dice rolls, using Barbecues custom function. DiceTest.zip
December 8, 200421 yr Newbies Finding factorial by using custom functions- my first experiment recursive custom function
February 4, 200521 yr That's awesome. I was doing the same thing with a script, but this is SO much more flexible. I added a modifier (e.g. 3d6 + 4) to the function and took out one loop (at zero), which speeds it up slightly. See what you think: Roll ( DieNum ; DieSize ; DieMod ) Int ( Random * DieSize ) + 1 + Case ( DieNum > 1 ; Roll ( DieNum -1 ; DieSize ; DieMod ) ; DieMod ) Now I figure I'll expand the custom functions there to include different kinds of die rolls. Success based systems (a la White Wolf/Shadowrun), Wild Die systems (Shadowrun, Star Wars), Best of... (4D6, drop the lowest), and critical/failures (bold/color the result based upon whether the die hit the maximum or minimum result). Thanks for getting me started. I couldn't figure out how to do this. Maybe I should've read the FMP Dev edition manual.
Create an account or sign in to comment