1 Reply Latest reply on Jun 2, 2014 3:26 PM by philmodjunk

    how to selest 10 records random



      how to selest 10 records random


           Need to create a script to select 10 records from a database field random , then mark them ask check for  the next run of random records.

           sample:  I have a numeric field that is unique with a number,  now I want to pick 10 number :randomly and after this flag them ask pick, then next run it wont pick the same number.


           Thanks in advance

        • 1. Re: how to selest 10 records random

               After creating your table of numbers, use Replace field Contents with the calculation option specified to assign the value of the Random function to a different number field. If you then sort your records specifying this field as the only field in the sort order, they will be sorted into "random" order--much like shuffling a deck of cards.

               Then the first 10 records in this found set will be 10 randomly selected values just like dealing 10 cards off of the top of a shuffled deck.

               So this table requires a minimum of three number fields, Value, RandomKey, Selected

               Your Select 10 script would be:

               Enter Find Mode [] ---> clear the pause check box
               Set Field [ Selected ; 1 ]
               Set Error Capture [on]
               Perform Find []
               Sort Records [no dialog ; Restore] --> Sort on the RandomKey field
               If [ Get ( FoundCount ) > 10 ]
                  Go to Record/Request/Page [no dialog ; 11 ]
                  Omit Multiple Records [ no dialog ; Get ( FoundCount ) ]
                  Replace Field Contents [ YourTable::Selected ; 1 ]
               Else If [ Get  ( FoundCount ) = 10 ]
                  Replace Field Contents [ YourTable::Selected ; 1 ]
                  Show Custom Dialog ["Not enough unselected records remain to select 10" ]
               End IF

               This script produces a found set of 10 randomly selected records.