Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Randomly select n unique codes from 5mln table
Message
 
 
À
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:
00579617
Vues:
28
>>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

I think, this one is the best idea. I generally have the same, as Jan...
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform