Recently, I encountered some random numbers, randomly disrupted arrays, and other random processing problems in my project. Let's make a summary today. 1. the following code generates a random password with a specified length: [java] import java. util. random; public class test {/*** @ param args */public static void main (String [] args) {// TODO Auto-generated method stub System. out. println (genRandomNum (10 ));} /*** generate the password immediately ** @ param pwd_len * total length of the generated password * @ return password String */public static String genRandomNum (int pwd_len) {// 35 is because the array starts from 0 and 26 letters + 10 digits final int maxNum = 36; int I; // the random number int c generated Ount = 0; // The length of the generated password char [] str = {'A', 'B', 'C', 'D', 'E ', 'F', 'G', 'h', 'I', 'J', 'k', 'l', 'M', 'n', 'O ', 'P', 'Q', 'R','s ', 't', 'U', 'V', 'w', 'x', 'y ', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8 ', '9'}; StringBuffer pwd = new StringBuffer (""); Random r = new Random (); while (count <pwd_len) {// generate a Random number, take the absolute value, prevents negative numbers. I = Math. abs (r. nextInt (maxNum); // The maximum number of generated data is 36-1 if (I> = 0 & I <st R. length) {pwd. append (str [I]); count ++ ;}} return pwd. toString () ;}} 2. disrupt the order of an array and generate a random array. here we need to use the shuffle () method in the java tool Collections. The Code is as follows: [java]/*** immediately breaks down an ordered array */import java. util. arrayList; import java. util. collections; import java. util. iterator; import java. util. list; public class Shuffle {public static void main (String [] args) {shuffle ();} public static void shuffle () {int [] x = {1, 2, 3, 4, 5, 6, 7, 8, 9}; List list = new ArrayList (); for (int I = 0; I <x. length; I ++) {System. out. print (x [I] + ","); list. add (x [I]);} System. out. pr Intln (); Collections. shuffle (list); Iterator ite = list. iterator (); while (ite. hasNext () {System. out. print (ite. next (). toString () + ",") ;}} 3. randomly retrieve the specified n number from the array. The Code is as follows: [java]/*** Description: Randomly retrieve the specified n number from the array. * @ Param ArrayList original array * @ param int n number of random extracts * @ return returns the extracted array */public static ArrayList getRandomArray (ArrayList list, int num) {ArrayList aList = new ArrayList (); for (int I = 0; I <num; I ++) {int randomNum = getRandom (list. size (); aList. add (list. get (randomNum); list. remove (randomNum);} return aList}. Write so much first, and then update it if there is a "random" problem.