//MSDN
Randomize
To generate a random integer within a range, use the following formula: Int((upperbound-lowerbound+1)*Rnd+lowerbound)
Here, upperbound is the upper limit of the random number range, and lowerbound is the lower limit of the random number range.
----The random function in VB is Rnd, but during the process of using it, I found that although the values generated after the program is started are random, the program will generate the same random number sequence every time it is restarted. What should I do? solve?
----The prototype of the random function in VB is: Rnd(number). The Rnd function returns a value less than 1 but greater than or equal to 0. The value of number (optional) determines how Rnd generates random numbers. Due to the determination of the way to generate random numbers, every time the random function is started, the initially given seed will generate the same sequence, because every time the Rnd function is called, the previous number in the sequence is used as the seed for the next number.
----In order to have a different random number sequence every time the running program calls the random function, before calling Rnd, first use the parameterless Randomize statement to initialize the random number generator, which has a seed obtained according to the system timer. In this way, if you call Rnd again, you will get a different random number sequence.
----In addition, according to the working principle of Randomize, users can also compile their own random functions, that is, use the function Timer to get the number of seconds that have passed from midnight to now, and then "calculate" the value according to the size of the random value to be obtained. Attenuation" processing, the value obtained in this way can be called a truly random value.