General information
Category:
Coding, syntax & commands
Title:
Random Record Selection Problems.
I need to create a randomly selected 20% sample on a table. Here is the code that I use:
SELECT finallist
ALTER table finallist ADD COLUMN RandSel n(1,0)
FOR i = 1 TO INT(reccount()*.2)
LOCATE for RECNO() = INT(RAND()*RECCOUNT())
IF finallist.RandSel <> 1 then
replace RandSel WITH 1
ELSE
SKIP 1
replace RandSel WITH 1
ENDIF
ENDFOR
SELECT * from finallist WHERE RandSel = 1 INTO TABLE RandomList
The problem that I am encountering is the function INT(RAND()*RECCOUNT()) changed value every time a new line of code gets executed. This seems to work with STEP ON. In the debug window I can watch the value of that expression change every time a line of code is ececuted. Is there a way to stop that or to do it different?
Any suggestions would be appreciated.
Thanks
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only