Random selection of records 
Author Message
 Random selection of records

Greetings.. was wondering if anyone had any quick tips on printing "n"
records from a data file.. for example, a .dbf with 50 records, what would
be the easiest way to randomly select 10 for printing?  Any ideas would be
greatly appreciated.  Thanks in advance.

*************************************************************************
*  Ralph Young                        * "If you're not part of the      *
*  U.S. Patent & Trademark Office     *  solution then you're part of   *
*  703-308-4211                       *  the problem."                  *

*************************************************************************
*  Any opinions are mine alone and do not reflect the views of          *
*  the U.S. Patent & Trademark Office                                   *
*************************************************************************



Sun, 17 Nov 1996 21:44:32 GMT  
 Random selection of records
: Greetings.. was wondering if anyone had any quick tips on printing "n"
: records from a data file.. for example, a .dbf with 50 records, what would
: be the easiest way to randomly select 10 for printing?  Any ideas would be
: greatly appreciated.  Thanks in advance.

You could use the RAND function, as follows:

=RAND(-1) && Seed the random-number generator
FOR m.Count = 1 TO 10
  GO (INT(RAND() * 49 + 1))  && will generate a number 1-50
  * Print the record
ENDFOR

I don't know how "random" the RAND function is (I suspect there may be
better random functions than FoxPro's), but this should work pretty
well.

If you want to make sure that a record doesn't get repeated (though it
wouldn't be random then), try keeping track of the numbers as follows:

=RAND(-1)
DIMENSION Numbers[10] && A place to store used numbers
Numbers = -1  && Set them all to a number we'll never get
FOR m.Count = 1 TO 10
  m.Rec = INT(RAND() * 49 + 1)
  DO WHILE ASCAN(Numbers, m.Rec) != 0  && Loop until we get a new number
    m.Rec = INT(RAND() * 49 + 1)
  ENDDO
  Numbers[m.Count] = m.Rec
  GO (m.Rec)
ENDFOR

Hope this will help.
Pete Kruckenberg



Mon, 18 Nov 1996 11:24:27 GMT  
 Random selection of records
-> Greetings.. was wondering if anyone had any quick tips on printing "n"
-> records from a data file.. for example, a .dbf with 50 records, what would
-> be the easiest way to randomly select 10 for printing?  Any ideas would be
-> greatly appreciated.  Thanks in advance.

How do you want to print them?  Are you using a programmed report or one of the
report writing tools?

Anyways, provided you had a small set, create an array with as many elements as
records in your original file.
   Then using the RAND() function, proceed to generate integers in the range of
   1-N, where N is the number of records.
      Because you cannot reuse the values, go to that element in the array.
         If the value is 0 then either print the record or copy to a holding
         table. Also increment your found record counter.
      Increase the value in the array.
   Stop when you have found your desired number of records.

Regards,

Derek Jubb
Manager, Information Systems
Retirement Counsel of Canada



Thu, 21 Nov 1996 22:20:00 GMT  
 Random selection of records
Quote:

>-> Greetings.. was wondering if anyone had any quick tips on printing "n"
>-> records from a data file.. for example, a .dbf with 50 records, what would
>-> be the easiest way to randomly select 10 for printing?  Any ideas would be
>-> greatly appreciated.  Thanks in advance.

Try this...

mytable = sys(3)
select *, .f. as include into table (mytable)
[ do some random function to set your ten records ]
report form <blahblah> for include
erase (mytable-".dbf")



Sat, 30 Nov 1996 11:54:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. random record selection

2. random numbers not random

3. Random Error 1502 Record in use by another

4. Best method - selection list of ALL records

5. Competing record selection methods

6. Mult-user record selection?

7. Please help me with record selection!!

8. SQL, selection records where 2 agregated fields are not equal

9. SQL-Select Record no of table1 (table 2 for selection)

10. Grid record selection

11. Looking for VFP function to generate random passwords

12. random numbers

 

 
Powered by phpBB® Forum Software