C # Generate random number instances

Source: Internet
Author: User

The example in this article describes how C # generates random numbers. Share to everyone for your reference. Specific as follows:


The code is as follows:

<summary>

Generate NUM digit Verification code for SMS verification function

</summary>

public static Random Rand = new Random ();

public static string getcode (int num)

{

string result = "";

string s = "uabcdefghijklmnopqrstuvwxyz0123456789";

for (int i = 0; i < num; i++)

{

int k = ((rand. Next (1, +) + i * 6)% 36) + 1;

result = String. Format ("{0}{1}", result, s[k]);

} return result;

}

Random r = new Random (); Create a random number generator

int v= R.next (1, 101); Get a random number that is less than or equal to 1 and less than 101. That is: Take a value between 1-100 (including 1, and 100)

In addition to the Declaration, Running GuestArticles are original, reproduced please link to the form of the address of this article
C # Generate random number instances

This address: http://www.paobuke.com/develop/c-develop/pbk23171.html






Related content WPF button overload style workaround for TCP sticky packet problem in C # Learning notes-Basic Syntax C # simple implementation of a case for sending mail on a Web page
C # to read the entire file contents into a string variable C # implements fetching and analyzing Web page class instances on the problem of the C # algorithm on bull calves Three kinds of scenario analysis of C # thread synchronization

C # Generate random number instances

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.