Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Problem with Rand()
Message
 
 
À
27/10/2010 11:07:58
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivie
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MySQL
Application:
Desktop
Divers
Thread ID:
01487156
Message ID:
01488384
Vues:
63
>>Hello,
>>
>>I'm having a problem with Rand(): after starting the application, it always generates the same Rand() values.
>>
>>How can I get really random values in VFP?
>
>James Blackburn gave you the answer, but I want to add some theory. Really random numbers are rarely used on computers, because that would require special hardware (for example, detect the decay of radioactive isotopes, or amplify random electrical noise in a wire). Instead, so-called pseudo-random numbers are usually used, and they are appropriate for many applications. In these, each number in a "random" sequence is actually calculated on the basis of the previous one - therefore you get the same sequence every time. The complete sequence can go through thousands or perhaps even millions of numbers before repeating, and the function is chosen so that the result "looks random".
>
>rand(-1) will "seed" the random number generator, basing it on the current time. Since this will not be the same the next time you run your program, you will get a different sequence.

Thanks for the explanation, this really helps me undestand why I need to do the seed. I was already wondering.
Christian Isberner
Software Consultant
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform