Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Selecting a Winner
Message
De
05/06/1999 04:52:39
Dragan Nedeljkovich (En ligne)
Now officially retired
Zrenjanin, Serbia
 
 
À
04/06/1999 14:07:17
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00226460
Message ID:
00226793
Vues:
29
>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 :)

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform