× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



JMBauman@xxxxxxxxxxxxxxxx wrote:
Wanted to get some feedback about possible options to pull random records
from a file.   I am dealing with an invoice file for a date (one day) for
multiple locations.  I need to pull thirty random bills from this file for
a date and the number of bills I pull for a location must be proportionate
to that location's number of bills compared to number of bill's for all
locations.  With that being said, my quandary is how to pull these bills
randomly.  My first attempt at this, I read through the file and selected a
record every "random" number of seconds.  This was not random enough as I
was always grabbing my bills from the first hundred records for every
location (about 500 records per location).  Any thoughts would be greatly
appreciated.


First, get the number of records in the file. After the file is opened, the number is in position 156-159 in the INFDS.


Next, use your favorite method to compute random numbers (such as the C runtime library function "rand()"), and convert them to the range computed in the first step. Compute as many as you need, checking for duplicates.

Finally, read the records by relative record number.

Cheers! Hans


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.