Java generates random number code

Source: Internet
Author: User

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

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.