6 Replies Latest reply on Dec 2, 2014 12:18 PM by jabond

    Picking a random set of records, with no repeats.

    jabond

      Good morning all,

       

      I'm stuck. Here is what I'm trying to do...from a list of 240 records, pick 60 random records, marked them as being "used" and then when the script runs again, pick another random set from the remaining records. What I need is to use each record once with no repeats, and end up using all the records in the end. In the example above, I would create 4 lists of 60 randomly picked questions from the list, while not reusing any of the questions. I hope I'm making sense.

       

      The only thing I have working right, is picking the random set of 60 records, but each time I run it, the number of records increases with each run (60, 120, 180, etc.)

       

      Here is the script I'm using the find and mark the random questions

       

      Go to Layout ["Question List 2" (Questin List 2)]

      Enter Find Mode []

      Insert Text [Select;Questions List 2::Marked; "Used"]

      Omit Record

      Perform Find []

       

      Replace Field Contents [No dialog; Question List 2::RandomField; Random]

      Sort Records [Restore; No dialog]

      Go to Record/Request/Page [First]

      Omit Multiple Records [No dialog; 60]

      Show Omitted Only

       

      Go to Record/Request/Page [First]

      Loop

      Insert Text [Select; Question List 2::Marked; "Used"]

      Go to Record/Request/Page [Next;Exit after last]

      End Loop

       

      Thanks in advance for any help!

       

      James.

        • 1. Re: Picking a random set of records, with no repeats.
          coherentkris

          Seems like Set Field is a better choice than Insert Text for your find. Wont fix your issue tho

          • 2. Re: Picking a random set of records, with no repeats.
            jabond

            Hi coherentkris,

             

             

            The original script used the "set field" command and it ran the same way.

            Changing it to "Insert Text" was an attempt to modify the script, however

            both versions worked the same way.  No joy.

             

             

            James.

             

             

            Regards,

             

            James Bond | Flight Operations Auditor | W: 650.762.7340

             

             

            • 3. Re: Picking a random set of records, with no repeats.
              jbante

              Your set is increasing by 60 records each time because your already-"Used" records and your randomly selected records are both in the set of omitted records you wind up showing. Try omitting the non-selected records in the second section of your script instead:

               

              ...

              Replace Field Contents [No dialog; Question List 2::RandomField; Random]

              Sort Records [...]

              Set Variable [$numberOfRecordsToSelect; Value:60]

              Go to Record/Request/Page [$numberOfRecordsToSelect + 1]

              If [Get ( LastError ) = 0]

              Omit Multiple Records [Get ( FoundCount ) - $numberOfRecordsToSelect]

              End If

              ...

               

              An alternative that could be slower depending on how many records you have, but doesn't require you to have a RandomField polluting your data table, is to omit random records until your found set is the size you want:

               

              ...

              Set Variable [$numberOfRecordsToSelect; Value:60]

              Loop

              Exit Loop If [Get ( FoundCount )] ≤ $numberOfRecordsToSelect]

              Go to Record/Request/Page [Ceiling ( Get ( FoundCount ) * ( 1 - Random ) )]

              Omit Record

              End Loop

              ...

              • 4. Re: Picking a random set of records, with no repeats.
                Mike_Mitchell

                James -

                 

                What your script is doing is marking individual groups of 60 records as "Used", until all records are marked as "Used". Is that what you want? Because your original question says it is, but you seem to imply that this is not the result you're after. If you're wanting 4 separate groups, then you're going to have to do something to mark them separately (i.e., don't use "Used" on every repetition).

                 

                Mike

                 

                P.S. Your difficulty also may be coming from misunderstanding that you have only two groups - either found, or omitted. When you omit the first group - "Used" records - and then you omit the first 60 in the next group, they all fall into the "Omitted" category. The second branch of your script then loops over the "Omitted" records and marks them all as "Used", whether they were marked that way originally or not. So you're going to have to change that logic if you want to use something other than a simple "Used" / "Not Used" designation.

                • 5. Re: Picking a random set of records, with no repeats.
                  jabond

                  Hello jbante,

                   

                  Ah! Thank you. It definitely makes sense. I'll give both options a try and

                  report back. Appreciate your help and clarification on the Omit function.

                   

                   

                  Regards,

                   

                  James Bond | Flight Operations Auditor | W: 650.762.7340

                   

                   

                  • 6. Re: Picking a random set of records, with no repeats.
                    jabond

                    Hi Mike_Mitchell,

                     

                    Thank you! I surly misunderstood the Omit function.  I was marking each set

                    of 60 "Used" thinking I could find remaining records more easily. The

                    misunderstanding was each time the script ran, the next set of 60 were

                    added to the initial set of omitted records.

                     

                    Appreciate the help!

                     

                     

                    Regards,

                     

                    James Bond | Flight Operations Auditor | W: 650.762.7340

                     

                     

                     

                    On Tue, Dec 2, 2014 at 11:54 AM, Mike_Mitchell <noreply@filemaker.com