>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)
>SELECT table
>COUNT TO nMaxValue FOR !DELETED()
>nWinnerRecord=INT(1+RAND()*nMaxValue)
>GO nWinnerRecord
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 :)