CopyCode The Code is as follows: // <summary>
/// Return a random number
/// </Summary>
/// <Param name = "vcodenum"> </param>
/// <Returns> </returns>
Public String rndnum (INT vcodenum)
{
String vchar = ";
String [] vcarray = vchar. Split (',');
String vnum = ""; // stringbuilder is not required because the string is short.
Int temp =-1; // record the previous random value. Avoid producing several identical random numbers.
// Use a simple Algorithm To ensure different random numbers are generated
Random Rand = new random ();
For (INT I = 1; I <vcodenum + 1; I ++)
{
If (temp! =-1)
{
Rand = new random (I * temp * unchecked (INT) datetime. Now. ticks ));
}
// Int T = Rand. Next (35 );
Int T = Rand. Next (9 );
If (temp! =-1 & temp = T)
{
Return rndnum (vcodenum );
}
Temp = T;
Vnum + = vcarray [T];
}
Return vnum;
}
only string code = rndnum (4) is required for the call.
a four-digit random number is obtained.
If a random letter is required,
string vchar = ", a, B"; Add the letter.
modify int T = Rand at the same time. in next (9);, 9 is changed to the length of vchar but can.