1 and Math.random () are common codes in Java language, which make the system randomly select pseudo-random double-precision values greater than or equal to 0.0 and less than 1.0. For example: double a = math. Random () * (3- 1)+ 1, set a random variable from 1 to 3.
2. Generate a 4-digit random string code, as shown below:
Public? Static electricity Invalid? main(String[]args){
String? Result = "";
for(inti = 0; I<4; i++){
//Generate an integer of 97- 122.
int? int value =(int)(math . random()* 26+97);
//Convert intValue to char type, followed by result.
result = result+(char)int value;
}
//Output string
System.out.println (result);
}