///The random letters and numbers are generated according to different difficulty
for (int i=0; Readomnumstart.length () <4; i++) {
if (difficult = = 1) {
//Generation with Number of 0-9 of the machine
A = string.valueof ((int) (Math.random () *));
if (difficult = 2) {
//is randomly generated in 0-9 and A,b,c,d.
String[] Readomword = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "B", "C", "D"};
int readomwordindex = (int) (Math.random () * 13);
A = Readomword[readomwordindex];
}
if (difficult = = 3) {
///Generate random letter
Char readomletter = (char) (Math.random () *26+ ' a ');
A = STRING.V Alueof (Readomletter);
}
if (difficult = = 4) {
///Generate random combination of numbers and letters
string[] Readomhard = new STRING[20];
Int Readomwordindex = (int) (Math.random () * 19);
for (int j=0; j<20; J + +) {
int readomwordnum = (int) (Math.random () *);
Char readomletter = (char) (MATH.R Andom () *26+ ' a ');
if (readomwordnum% 2 = 0) {
Readomhard[j] = Readomwordnum + "";
} else{
Readomhard[j] = string.valueof (readomletter);
}
}
a = Readomhard[readomwordindex];
}
//
This writing code is relatively short. I have also consulted a lot of people's code most of them are complex. I don't like to write so much code, so I wrote it. Do not know this write efficiency is not a problem, on my computer to run without any feeling.