Import java.util.random;/* Random number class: Write a function to randomly generate a four-bit verification code. */public class Demo5 {public static void main (string[] args) {/*random random = new random (); int randomnum = Random.nextin T (10) +1; The resulting random number is between 0-10 System.out.println ("Random number:" + randomnum); */char[] arr = {' In ', ' country ', ' pass ', ' a ', ' Q ', ' f ', ' B '}; StringBuilder sb = new StringBuilder (); Random random = new random ();//requires four random numbers to get the characters in the character array by random number, for (int i = 0; i< 4; i++) {int index = Random.nextint (Arr.leng TH); The resulting random number must be within the range of the index value of the array. Sb.append (Arr[index]);} System.out.println ("Verification Code:" + SB);}}
Java writes a four-digit random verification code