Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Selecting 10 records randomly
Message
De
04/01/1998 12:38:46
 
 
À
04/01/1998 12:29:19
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00069291
Message ID:
00069350
Vues:
38
>>>>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().

Basically, if you have two GO somewhere commands one after another, the first one is surely useless.

Vlad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform