Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Selecting a Winner
Message
De
05/06/1999 09:37:16
 
 
À
05/06/1999 04:52:39
Dragan Nedeljkovich (En ligne)
Now officially retired
Zrenjanin, Serbia
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00226460
Message ID:
00226820
Vues:
23
Yes, that works.


>>Hi Bruce, Gary:
>>
>>Good idea, Bruce...here be da code
>
>John, if you're assuming there may be deleted records, then you may land on a deleted record
>
>>=RAND(-1)                  && Initialize to system clock
>>SELECT table
>>COUNT TO nMaxValue FOR !DELETED()
>>nWinnerRecord=INT(1+RAND()*nMaxValue)
>>GO nWinnerRecord   && This is the winning record
>
>
>Therefore, I'd do something like this:
>
>=RAND(-1) && Initialize to system clock
>SELECT *, recno() as nRecno from TheTable ;
> into curs zzz where !DELETED()
>nWinnerRecord=INT(1+RAND()*recc())
>GO nWinnerRecord && This is the copy of the winning record
>nOriginalRecno=nRecno
>select TheTable
>go nOriginalRecno && now there we are
>
>
>I did have some random picks like yours, and when I pick a record which doesn't fit (in this case it's a deleted record, in my case I had some other criteria), I tried to skip the unfit records - and didn't like the result, because I landed on the same record much too often. The wrong records usually don't have an uniform distribution. For a large table, this may be an overkill, but then, the stakes may be high and we may choose to neglect the cost... and raise our own percentage :)
------------------------------------------------
John Koziol, ex-MVP, ex-MS, ex-FoxTeam. Just call me "X"
"When the going gets weird, the weird turn pro" - Hunter Thompson (Gonzo) RIP 2/19/05
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform