Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Random numbers - the most efficient way
Message
 
 
À
07/09/2004 23:39:16
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00939849
Message ID:
00940338
Vues:
37
Al,

That threw me too, but I think you are supposed to use the result of the ? command as the list of randomized cards, not the final array itself.

>I'm not sure this routine is reliable in the general case. For example, it should work if, say, RAND() always returned 0.5. If I modify it as follows (using only 5 cards for illustration):
DIMENSION aCards[5]
>FOR x=1 TO 5
>  aCards[x] = x
>ENDFOR
>RAND(0)
>FOR x=5 TO 1 STEP -1
>  nRnd = INT(0.5*x) + 1
>  nMax = aCards[x]
>  ? aCards[nRnd]
>  aCards[nRnd] = nMax
>ENDFOR
>
>* 5 array values are 1, 4, 4, 4, 5
df (was a 10 time MVP)

df FoxPro website
FoxPro Wiki site online, editable knowledgebase
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform