Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Selecting a Winner
Message
From
05/06/1999 04:52:39
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
 
 
To
04/06/1999 14:07:17
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00226460
Message ID:
00226793
Views:
27
>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.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform