How does a real random function occur? _vb

Source: Internet
Author: User
Tags generator
Msdn
Randomize

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

Here, the upperbound is the upper limit of the range of random numbers, and the lowerbound is the lower bound of the range of random numbers.


The random function of----in VB is RND, but it is found in the process of using, although the numerical value produced after the program starts is random, but for each reboot, the program will produce the same random number sequence, how should we solve it?

The prototype of a random function in----VB is: Rnd (number), 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. Because the generation of random numbers is determined, each time a new starting random function is generated, the initial given seed generates the same sequence, because each call to the RND function uses the previous number in the sequence as the seed of the next number.

----There are different sequences of random numbers in order to call random functions every time the program is run. Before calling Rnd, the random number generator is initialized with a randomize statement without parameters, and the generator has seeds based on the system timer, so that a different sequence of random numbers can be obtained by invoking the Rnd.

----In addition, according to the working principle of randomize, users can also develop their own random function, that is, using function timer to get the number of seconds from midnight to now pass, and then based on the random number of values to be obtained to "decay" the value of the processing, The resulting numerical value can be called the true meaning of the 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.