Jump to content
Server Maintenance This Week. ×

My first recursive custom function...


This topic is 7027 days old. Please don't post here. Open a new topic instead.

Recommended Posts

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!

Link to comment
Share on other sites

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.)

Link to comment
Share on other sites

  • 1 month later...

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. laugh.gif

Link to comment
Share on other sites

This topic is 7027 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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.