Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Randomly select n unique codes from 5mln table
Message
De
09/11/2001 07:49:37
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
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:
00579584
Vues:
28
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...

Nadya,
Discard my previous msg (I really thought it was 'Friday' yesterday and didnt have time to think just wrote and left work - shouldn't do).
Table is huge so my approach would be almost same as already presented by Jay and Hilmar.
local lnRecsToCollect, lnRecs
local array arrUnique[1]

lnRecsToCollect = 110
lnRecs = reccount('HugeTable')

create cursor crsCodes (rcno i, icode i) && Better would be a PK and adjust code type

rand(-1)
do while alen(arrUnique) < lnRecsToCollect
 go ceiling(rand()*lnRecs) in 'HugeTable'
 if ascan(arrUnique,HugeTable.icode)=0
   dimension arrUnique[iif(type('arrUnique')='L',0,1)+alen(arrUnique)]
   arrUnique[alen(arrUnique)]=HugeTable.icode
   insert into crsCodes values (recno('HugeTable'),HugeTable.icode)
 endif
enddo
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform