Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Random Record Selection Problems.
Message
De
15/12/2003 16:10:05
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivie
 
 
À
15/12/2003 15:22:26
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00859259
Message ID:
00859296
Vues:
15
For many purposes, you can select one out of every 5 records. Judge for yourself whether this is "random" enough for your purposes, or not.
use MyTable
copy to Sample for recno() % 5 = 0
>I need to create a randomly selected 20% sample on a table. Here is the code that I use:
>
>SELECT finallist
>ALTER table finallist ADD COLUMN RandSel n(1,0)
>
>FOR i = 1 TO INT(reccount()*.2)
> LOCATE for RECNO() = INT(RAND()*RECCOUNT())
> IF finallist.RandSel <> 1 then
> replace RandSel WITH 1
> ELSE
> SKIP 1
> replace RandSel WITH 1
> ENDIF
>ENDFOR
>
>SELECT * from finallist WHERE RandSel = 1 INTO TABLE RandomList
>
>The problem that I am encountering is the function INT(RAND()*RECCOUNT()) changed value every time a new line of code gets executed. This seems to work with STEP ON. In the debug window I can watch the value of that expression change every time a line of code is ececuted. Is there a way to stop that or to do it different?
>
>Any suggestions would be appreciated.
>
>Thanks
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform