ASP. NET generates N-bit verification Codes

Source: Internet
Author: User

// Random extraction from strchar array in the random number generation function
// Uppercase/lowercase letters
// Parameter n is the number of digits that generate a random number. Generally, four digits are used.
Public String randomnum (int n )//
{
String strchar = ";
String [] vcarray = strchar. Split (',');
String vnum = ""; // stringbuilder is not required because the string is short.
Int temp =-1; // record the last random value, and try to avoid several identical

Number of machines
// Use a simpleAlgorithmTo ensure different random numbers are generated
Random Rand = new random ();
For (INT I = 1; I <n + 1; I ++)
{
If (temp! =-1)
{
Rand = new random (I * temp * unchecked (INT)

Datetime. Now. ticks ));
}
// Int T = Rand. Next (35 );
Int T = Rand. Next (10 );
If (temp! =-1 & temp = T)
{
Return rndnum (N );
}
Temp = T;
Vnum + = vcarray [T];
}
Return vnum; // return the generated random number.
}
After a random number is generated, assign the value to a label control and change the color of the label background. OK.

Thank you for reading!

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.