vb.net to get the random number within a specified range __.net

Source: Internet
Author: User

Recently need to do a random sampling of the small program, studied the vb.net under the random number of methods:

First, we do a trial, using the Rnd () function +math.round (), for example, I would like to take a random number within 1-100 (the result should probably contain 1 and 100)

Math.Round (Rnd () * 100)

Did a 1000 cycle sampling, found that the result contains 0-100 of the possible, but the random out of the 0 is not the result I want, and then replace the following more convenient way to achieve:

Dim myrnd as New Random
myrnd.next (1, 101)

After instantiating a random object, using the next (A,b) method to take random numbers, where the random results from a to b-1 may be, so to achieve 1-100 random, you should use Next (1,101) on it, or do a 1000 times cycle test, the results meet the demand ~

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.