How to generate real random functions?

Source: Internet
Author: User

// MSDN
Randomize

To generate a random integer in a range, use the following formula: Int (upperbound-lowerbound + 1) * Rnd + lowerbound)

Here, upperbound is the upper limit of the random number range, while lowerbound is the lower limit of the random number range.

---- The random function in VB is Rnd, but it is found that although the value generated after the program is started is random, for each restart, the program generates the same random number sequence. How can this problem be solved?

---- The prototype of the random function in VB is Rnd (number). The Rnd function returns a value smaller than 1 but greater than or equal to 0. The value of number (optional) determines how Rnd generates a random number. Due to the determination of the random number generation method, each time a random function is started, the initial seed will generate the same series, because each call to the Rnd function uses the previous number in the sequence as the seed of the next number.

---- Each time a program calls a random function, there will be different random number sequences. Before calling Rnd, use the Randomize statement without parameters to initialize the random number generator, the generator has a seed based on the system timer, so that different random number sequences can be obtained by calling Rnd.

---- In addition, according to the working principle of Randomize, you can also compile your own random functions, that is, use the Timer function to get the number of seconds that have elapsed since midnight, then, we take the desired random value for "attenuation" processing. The obtained value can be called a real random value.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.