Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Selecting a Winner
Message
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00226460
Message ID:
00226926
Views:
31
>>>=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
>>
>>:)) You forgot the deleted records just before your last line of code. :)
>
>I thought he just assumed SET DELE ON, the usual state, so COUNT will return only the non-deleted records. After all, if it's OFF, then the code can break anyway, since you may GO to a deleted record...so his code is either okay, or else the slight addition of !DELETED() will not help it...make sense?

Let me add that if there are deleted records, the code can still break...if there are deleted records, better to PACK or dump into a cursor before the code is applied...not as simple as everyone thought at first, I guess :)
The Anonymous Bureaucrat,
and frankly, quite content not to be
a member of either major US political party.
Previous
Reply
Map
View

Click here to load this message in the networking platform