// The following code is frequently used in the ASP. Net user logon interface:
Private void page_load (Object sender, system. eventargs E)
{
// Place user code here to initialize the page
Label4.text = randomnum (4 );
}
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 to avoid the generation of several identical random numbers.
// Use a simple algorithm to 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.
}
// ''Function name: rndnum
// ''Function parameter: vcodenum -- set the number of digits returned to a random string
// ''Function: generate a random string mixed with numbers and characters
Private string rndnum (INT vcodenum)
{
String vchar = ", A, B, C, D, E, F, G, H, I, J, K, L, M, n, O, P, Q, R, S, T, U, w, x, y, z ";
String [] vcarray = vchar. Split (",". tochararray (); // generate an array of strings
String vnum = "";
Int I;
For (I = 1; I <vcodenum; I ++)
{
System. Random RO = new random ();
Double Deca = Ro. nextdouble ();
Vnum = vnum + vcarray [convert. toint32 (35 * DECA)];
}
// For I = 1 to vcodenum
// Randomize
// Vnum = vnum & vcarray (INT (35 * RND) ''array is generally read from 0, so here it is 35 * RND
// Next
Return vnum;
}
// The user verification code on the ASP. Net Logon interface. Collect and test the code on the network.
// Http://www.weste.net/2006/2-24/14492415770.html
// Http://www.webdn.com/web_file/program/asp.net/0602080581/