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.

Selecting random records from found set

Featured Replies

Hi all

I have the current script below set to find a random number of records based on the test question requirement (TestQuestionCount) within a found set. The script successfully is able to isolate x number of questions depending on the TestQuestionCount requirement. I have watched the Data Viewer during script debugging. However, if the question count requirement is 30 questions, it's usually finding ~25 records or so. Upon further investigation I see it is randomly (of course) capturing duplicate record ID's. When the system is creating a new request there are usually a couple duplicates, thus my found set is not matching the TestQuestionCount. The error I believe is happening at the beginning of the first Loop below, but I'm unable to determine where I've gone wrong.

A keen eye appreciated.

 

Set Error Capture [On]
Set Variable [ $maxQuestions ; Value: ACS PTS Type::TestQuestionCount ]
If [ Get (FoundCount ) ≤ $maxQuestions
	Exit Script
End If
# Get a list of randomly selected records from the found set
Loop
	Set Variable [ $n ; Value: Round ( Random * Get (FoundCount) ; 0 ) + 1 ]
    Set Variable [ $id.list ; Value: List ( $id.list ; GetNthRecord ( Questions::PrimaryKey ; $n )) ]
    Omit Record
    Exit Loop If [ ValueCount ( $id.list ) = $maxQuestions or not Get (FoundCount) ]
End Loop
#Find selected records
Enter Find Mode [ Pause: Off ]
Loop
	Set Field [ Questions::PrimaryKey ; "==" & GetValue ( $id.list ; Get (RecordNumber )) ]
    Exit Loop If [ Get (RequestCount ) = $maxQuestions ]
    New Record/Request
End Loop
Perform Find [ ]

 

The problem is that you are omitting a record, not necessarily the record you have selected. Thus the selected record can remain in the found set and be selected again.

A better method would go to a random record from the current found set*, add its ID to the list and omit it. This eliminates the possibility of selecting the same record twice.

---
(*) See here how:
https://fmforums.com/topic/100245-building-a-quizzing-flashcard-system/?do=findComment&comment=456349

 

  • Author
14 minutes ago, comment said:

The problem is that you are omitting a record, not necessarily the record you have selected. Thus the selected record can remain in the found set and be selected again.

A better method would go to a random record from the current found set*, add its ID to the list and omit it. This eliminates the possibility of selecting the same record twice.

---
(*) See here how:
https://fmforums.com/topic/100245-building-a-quizzing-flashcard-system/?do=findComment&comment=456349

 

Thanks, comment. Nailed it.

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.