Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Selecting 10 records randomly
Message
De
04/01/1998 01:39:32
 
 
À
04/01/1998 00:32:56
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00069291
Message ID:
00069314
Vues:
31
>>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?

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

Click here to load this message in the networking platform