Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Randomly select n unique codes from 5mln table
Message
From
08/11/2001 13:18:01
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00579211
Message ID:
00579237
Views:
26
This message has been marked as a message which has helped to the initial question of the thread.
>Hi everybody,
>
>How can I randomly select n (110) codes from some huge table, so these codes would be unique? I'm trying to create a test case now...
*   Assumes V. 7 for RW cursor, but can emulate in prev versions.

SELECT cCodes, .F. AS lSelected ;
   FROM BigTable ;
   INTO CURSOR UniqueCodes readwrite ;
   GROUP BY cCodes

lnCodes = _Tally

SELECT UniqueCodes

*  This approach to using RAND() will give randomized numbers, but
*  the same sequence each time it is run (this is helpful for testing
*  to determine that changes in execution speed are due to algorithm
*  changes rather than the distribution of the values).

*  If you want a different series between runs, you can issue a
*  preliminary call to RAND (-1) which will seed with a value
*  from the system time clock. For that, uncomment the line below

*  = RAND (-1)

lnSelected = 0
DO WHILE lnSelected < 110
   GO lnCodes * RAND () + 1
   IF NOT lSelected
       REPLACE lSelected WITH .T.
       lnSelected = lnSelected + 1
   ENDIF
ENDFOR

SELECT cCodes ;
   FROM UniqueCodes ;
   WHERE lSelected ;
   INTO CURSOR SelectedCodes
Enjoy!

Jay
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform