Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Random
Message
De
29/07/2009 22:41:26
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivie
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Re: Random
Versions des environnements
Visual FoxPro:
VFP 9 SP2
Divers
Thread ID:
01415429
Message ID:
01415461
Vues:
54
> Good function
>
> Do you think its really random, or based o system time or something like this ?

Do some reading on pseudo-random numbers, for example, http://en.wikipedia.org/wiki/Pseudorandom_number_generator. The Portuguese equivalent is only a stub, I am sorry to say - same problem with Spanish.) See also http://en.wikipedia.org/wiki/Hardware_random_number_generator

Usually no "real" random number generation are created in computers. It is possible, but requires specialized hardware. For example, it is easy to imagine, but difficult to implement, an apparatus that detects the exact moment of a radioactive decay. Since the underlying process is (according to current physical knowledge) inherently random, the result would "really" be random. You could also capture random electrical noise in a cable; this would probably be easier to implement. Remember, the movement of each electron has some truly random element! There is some Web site that offers random numbers generated that way.

In practice, some sequence is often used, where each pseudo-random number is calculated from the previous one; the sequence may always be the same, or the "seed" (the sart of the sequence) may be taken from the computer clock (random enough for most practical purposes). The sequence is chosen so that it "looks" random, at least for a casual observer. To make the sequence pass strict quality controls is a difficult subject. From the encyclopedia: "The generation of random numbers is too important to be left to chance." Funny, but true!

Notes on Visual FoxPro:

1. If you use rand() for random numbers, you should initialize the sequence from the system time, by using rand(-1) somewhere in the start of the program. Otherwise, you will always have the same sequence - at least if you run the executable from outside Visual FoxPro.

2. The resulting random number is such that x is between 0 and 1 (excluding 1); this can be manipulated to converted it to any other interval, get integers only, convert to letters, etc.
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform