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.

Need Random Calc within 1-8 Range

Featured Replies

I'm trying to create a field that will calculate a non-unique random number between a given range (1-8) for each record.

That is, each record out of 125, for example, would each have a random value between 1 and 8 for that field.

Solutions?

Truncate( Random* 7.1, 0 ) + 1

Adding 1 prevents 0 from being an option. Using 7.1 ensures adding 1 and truncating won't exceed 8.

If you require that the numbers be truly random (and therefore evenly distributed over a large sample) using 7.1 will not do, as it will ensure that the numbers 1 to 7 occur in the result with a frequency ten times that of the number 8. To achieve a random distribution of numbers from 1 to 8, I suggest you use:

Int(Random * 8) + 1

The Random function produces a number between zero and 1 (not inclusive). Since it will never equal either 0 or 1, multiplying it by 8 will produce a result which extends from 0.0000000000000001 to 7.99999999999999 (once the floating point limitation of 15 decimal places in FMP v6 is applied to it).

Applying Int( ) to this result will give an even distribution of integers from 0 to 7 inclusive, and only then will adding one give you the result you've asked for. wink.gif

Well dang, it was nice of FM to include that little detail regarding exclusivity in their help file. Luckily I haven't had need to use random numbers in my business.

I assume then, that Truncate(Random* 8, 0) + 1 would be satisfactory and similar to Int(Random* 8) + 1, though minorly more complex.

-Queue- said:

Well dang, it was nice of FM to include that little detail regarding exclusivity in their help file. Luckily I haven't had need to use random numbers in my business.

Yes. If it were inclusive, an unweighted distribution of results could be appropximated using Int(Random * 7.999) + 1. Not only is the online help entry on the Random function implicit rather than explicit, but the example it cites also contains several errors.

I assume then, that Truncate(Random* 8, 0) + 1 would be satisfactory and similar to Int(Random* 8) + 1, though minorly more complex.

Yep. Modestly over-engineered, but nonetheless effective... wink.gif

Create an account or sign in to comment

Important Information

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

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.