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

Picking a Random Record

Featured Replies

For an upcoming promotion, I need to be able to select a customer at random. Each customer has a unique number in my FM data base.

I'm trying to develop a script to accomplish that within FM. Possible? I have already created a field that I can mark customer records that are eligible (ie has an e-mail address and hasn't won before).

The perfect script would only scan the selected records and randomly select a record which would become the "winner".

Possible within FileMaker? -- jal

Hi,

You can do this using a set field and go to record commands in your script.

Create a global number field (lets call it gRandom) to hold the result

In your script add the following lines

Set Field [gRandom, Round(Random* (Status( CurrentFoundCount) - 1) + 1, 0) ]

Go To Record/ Request/ Page [by field value, gRandom]

HTH

  • Author

Very helpful!

That accomplishes what I need. Thank you. -- jal

  • 2 weeks later...

This formula keeps popping up from time to time, and it does not give an even probability for picking all records. The first and last record will always have exactly half the probability of being picked compared to the other records. To see what I mean, work out the math for a found set of 3 records.

Random value in the range 0 to .24999 returns record 1 (25% chance)

Random value in the range .25 to .74999 returns record 2 (50% chance)

Random value in the range .75 to .9999 returns record 3 (25% chance)

The culprit is the Round() function which skews the calculation.

The correct (and simpler) formula should be:

Int (Status(CurrentFoundCount)*Random)+1

Create an account or sign in to comment

Important Information

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

Account

Navigation

Search

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.