// 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!