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 14:38:53
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00579211
Message ID:
00579298
Views:
23
>>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...
>
>Ok, I have an idea by myself.
>1) Select code group by 1 into cursor curTemp
>
>2) Randomly find a number between 1 and _tally (repeat 110 times)
> Put each record with this recno() in temp table.

Hi Nadya,

I use the follwing to extract all kinds of things:
t_percent   = .05           && Percent of file to extract
t_type1     = 0             && number of filename.fieldname = 1 
t_recs_03   = 0             && counter for recordss held
t_cnttype   = 0             && filename.fieldname = 1 counter
t_pct_cnt   = 0             && recs to skip between extractions
USE filename in 0 ALIAS input EXCLUSIVE   
t_pct_nbr   = CEILING(t_type1 * t_percent)  && Whole number of recs to extract
t_pct_cnt   = CEILING(t_type1 / t_pct_nbr)  && Number of recs to skip
SCAN
   SCATTER MEMVAR
*)******************************************************************************
*) If the record doesn't have a fieldname = 1 AND MOD of t_type1 isn't a 0
*)     stick the record into both files;
*) If the record is a mailtype =1 and Mod of the t_type1 is 0
*)     make sshop = to "Hold" and stick the record only into the pctfile file,
*)     and add 1 to t_type1 for next go around
*)------------------------------------------------------------------------------
   DO CASE
      CASE m.fieldname = 1                  
         t_cnttype   = t_cnttype + 1
         IF MOD(t_cnttype, t_pct_cnt) = 0        
            m.fieldname2   = "Hold"
            INSERT INTO pctfile FROM MEMVAR
            t_recs_03  = t_recs_03 + 1
         ELSE
            INSERT INTO input   FROM MEMVAR
            INSERT INTO pctfile FROM MEMVAR
         ENDIF
      OTHERWISE
         INSERT INTO input FROM MEMVAR
   ENDCASE
ENDSCAN
It's written for FPW2.6, so please excuse the bad varnames
HTH,
Pete
Peter Adams
FoxPro Programmer
Compu-Mail

Heisenberg was probably right...
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform