Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Selecting 10 records randomly
Message
From
04/01/1998 01:37:19
 
 
To
04/01/1998 00:32:56
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00069291
Message ID:
00069312
Views:
34
>>I believe in simple things... :)
>>
>>n=reccount()
>>=rand(-1)
>>x=rand()
>>nextnumber = int(n*x)
>>
>>then save the number into array[10]
>>get nextnumber, check if it is already in array, if not save it there... 10 times in a row (or more :)
>
>Here's a similar version of what I finally did. I random the first and take 10 records from that position. You'll see that I applied a small verification to make sure we scroll from the first record if we are at the EOF() if we still haven't found 10 records. In this case, NUMERO is the unique key.
>
>SELECT NUMERO,.T. FROM QUESTION WHERE ... INTO CURSOR TEMP
>LOCAL lcInlist
>lcInlist=''
>GO BOTTOM
>GO INT(RAND(-1)*RECNO())+1
>FOR lnCompteur=1 TO 10
>   lcInlist=lcInlist+ALLTRIM(STR(NUMERO))+','
>   SKIP
>   IF EOF()
>      GO TOP
>   ENDIF
>NEXT
>lcInlist=SUBSTR(lcInlist,1,LEN(lcInlist)-1)
>SELECT NUMERO,TITLE,CREATION,NOTES FROM QUESTION;
> WHERE INLIST(NUMERO,&lcInlist) INTO CURSOR TEMP
>
So, you don't want to select 10 times randomly, but only once...

Vlad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform