Barbecue Posted November 30, 2004 Posted November 30, 2004 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!
Reed Posted November 30, 2004 Posted November 30, 2004 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.)
Barbecue Posted December 2, 2004 Author Posted December 2, 2004 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.
Michael Myett Posted December 3, 2004 Posted December 3, 2004 Here's a little utility to calculate the statistics of dice rolls, using Barbecues custom function. DiceTest.zip
Newbies RAJESH Posted December 8, 2004 Newbies Posted December 8, 2004 Finding factorial by using custom functions- my first experiment recursive custom function
iNik Posted February 4, 2005 Posted February 4, 2005 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.
Recommended Posts
This topic is 7300 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now