Wiki Home

Random Sample

Namespace: WIN_COM_API
There are several ways to get a random sample; I've used the following method for a long time now:
-- Tod McKenna

? get_sample(tablename,10)

FUNCTION get_sample
	LPARAMETERS tcTable, tnRecPerc
	LOCAL lnWorkArea AS Integer 
	lnWorkArea = SELECT()
	RAND(-1)		&& seeds based on the system clock
	SELECT TOP tnRecPerc PERCENT RAND()*100 AS rval, * ;
		FROM (tcTable);
		ORDER BY 1 ;
		INTO CURSOR crResults
	SELECT (lnWorkArea)

Contributors: Tod McKenna
Category Statistics
( Topic last updated: 2006.12.18 05:26:27 PM )