Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How to randomly generate four letters with js?
How to randomly generate four letters with js?
Random numbers are used for all random things. In js, the Math.random () method is used to get numbers between 0 and 1.

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);

}