Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Randomly select n unique codes from 5mln table
Message
 
 
To
09/11/2001 07:49:37
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00579211
Message ID:
00579617
Views:
29
>>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
Previous
Reply
Map
View

Click here to load this message in the networking platform