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.

random records

Featured Replies

  • Newbies

I need to select groups of 37 random records without repeating records. The database is about 900 records. Is there any way to do this?

Wyowater:

Welcome to the Forums.

A simple method for this would be to loop through the records and set a numeric field to random, then sort the records by that randomized field & take the first 37 records. The script step to randomize is:

Set Field [table::field; Random]

-Stanley

  • Author
  • Newbies

Thank you for the quick response. I will do it and let you know how I did. It's my first try at anything besides alphabetising in FM

Attached is a FM5 example of another method. This method's script only loops for as many random records as you want. It omits a record in each iteration and then does a Show Omitted after the loop completes.

Purists could argue that this algorithm may not be quite as random as Stanley's. Years ago I knew the theory of pseudo-random number generators, my experience tells me that any non-randomness will be negligible.

RandomRecs.zip

Sam:

That's a nifty solution, especially as it is much faster than randomizing the entire table. Also, I think it may actually be more random than what I posted, as FMP's random number generator can sometimes produce sequential numbers, and re-randomizing each time through the loop would negate that behavior.

-Stanley

Stanley->

I also made a loop that is more random and guarantees no duplicates. It doesn't loop through all records, but the Replace Contents step does. So it's not fast...

Show All Records

Replace Contents [Flag, 0]

Set Field [NumFlagged, 0]

Set Field [gTotalNumRecords, Status(TotalRecordCount)]

Loop

Set Field [gLoopCounter, 0]

Loop

Set Field [gRandomRecNumber, 1 + Round( Random gTotalNumRecords - 1 ))]

Go To Record [gRandomRecNumber]

Exit Loop If [not Flag]

Set Field [gLoopCounter, gLoopCounter + 1]

If ( gLoopCounter > gTotalNumRecords )

Do something to tell the user it blew up...

Exit Script

End If

End Loop

Set Field [Flag, 1]

Set Field [NumFlagged, NumFlagged + 1]

Exit Loop If [NumFlagged = 37]

End Loop

# A find can be performed to make the found set the random, or a relationship & portal can show them

Enter Find Mode []

Set Field [Flag, 1]

Perform Find

Hi to all friends

I think that this isn't the right place to post this question, expecially because wyowater owns FM5 !

Agreed, but wyowater is new to the forums and probably doesn't know the FileMaker definition of Custom Functions.

wyowater: FileMaker Developer (Advanced in 8) allows the developer to create Custom Functions that will appear in the function list in calculations..

BTW: is wyowater short for Wyoming Water?

  • Author
  • Newbies

Yes - The Bighorn River in Wyoming. It flows north and eventually into the Missouri River. The Bighorn River from the mouth of the Canyon to Thermopolis is some of the best fly fishing in the country - but don't tell anyone; it's a secret.

  • Author
  • Newbies

Also, thank you for the information. I'll try this tonight or tomorrow morning. I can't believe the GREAT help!!

  • Author
  • Newbies

I need some help with your Post#177912

In response to stanley.

In the second line - are "Contents" and "Flag" fields?

In the eighth line - I can't specify the last part ,1 + Round (Random gTotalNumRecords - 1 , 0 )

No matter what I put after the 0, it errors. I have tried ) and )) and 0] and ))]. The error is: A number, Text Constant, field name, or"(" is expected here. I also tried it the way you typed it with the same results.

wyowater->

"Flag" is a global number field. "NumFlagged", "gTotalNumRecords", "gLoopCounter", and "gRandomRecNumber" are also global number fields.

In the Replace Contents step, the Specified field is Flag and Specify... is Replace with calculated result, wtih 0 being the result entered into the dialog.

Oops, I made a couple of typos... The formula that goes in the script step dialog is:

1 + Round( Random* ( Status(CurrentFoundCount) - 1 ), 0 )

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.