Al,
>I agree that this technique is elegant. However, Nadya asks for "efficient" in the thread title. As a guess, I'd say this technique isn't that efficient. For example, if you are trying to pull 40 random records out of a million, this technique means a million records will be pulled over the wire, sorted, then the top 40 sliced off the top. Doing 40 random GOTOs in the same million-record table may be more efficient.
Most certainly if you have a huge table or slow network based file and only want a few records it's much more time efficient to do something like:
rand(-1)
lnRecs = reccount( "TheSampledTable" )
select * ;
from TheSampledTable ;
into cursor TheSample readwrite ;
where 1=2
do while reccount( "TheSample" ) < lnSampleSize
select TheSampledTable
goto int( lnRecs * rand() ) + 1
if ( ! deleted() )
scatter name oData memo
select TheSample
append blank
gather name oData memo
endif
enddo