Public class rondom { public static string genrandomnum (Int card_len) { &NBSP;&NBSP;&NBSP;//35 is because the array is starting from 0, 26 letters + 10 digits final int maxNum = 36; int i; //generated random number int count = 0; //the length of the generated password char[] str = { ' 0 ', ' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 ', ' 6 ', ' 7 ', ' 8 ', ' 9 ' }; StringBuffer pwd = new StringBuffer (""); random r = new random (); while (count < card_len) { //generates random numbers, takes absolute values, prevents the generation of negative numbers i = math.abs ( R.nextint (Maxnum)); //generates a maximum of 36-1 if (i >= 0 && i < str.length) { pwd.append (Str[i]); count ++; } } return pwd.tostring ();} Public static void main (String[] args) {for (int l=0;l<100;l++) { System.out.println (Genrandomnum (6));//Generate 6-bit random number}}}
Java generates a random number for a specified number of bits