Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Randomly select n unique codes from 5mln table
Message
De
08/11/2001 13:18:01
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00579211
Message ID:
00579237
Vues:
25
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform