Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

My first recursive custom function...

Featured Replies

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!

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

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

cool.gif

Here's a little utility to calculate the statistics of dice rolls, using Barbecues custom function.

DiceTest.zip

  • Newbies

Finding factorial by using custom functions- my first experiment recursive custom function

  • 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

Create an account or sign in to comment

Important Information

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

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.