Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Selecting 10 records randomly
Message
From
04/01/1998 12:29:19
 
 
To
04/01/1998 01:39:32
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00069291
Message ID:
00069345
Views:
41
>>>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
>>
>
>What's the use of the GO BOTTOM?

GO BOTTOM was used for the next line where I establish the range by using RECNO().

But, David's technique is doing the job in one line.
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform