Here you can find the source of getRandomString(int length)
Parameter | Description |
---|---|
length | a parameter |
public static String getRandomString(int length)
//package com.java2s; import java.util.Random; public class Main { public static String getRandomString(int length) { String RandomCode = ""; char[] codeSequence = { '3', '4', '5', '6', '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' }; Random random = new Random(); StringBuffer randomCode = new StringBuffer(); for (int i = 0; i < length; i++) { String strRand = String.valueOf(codeSequence[random.nextInt(40)]); randomCode.append(strRand);//from w ww . j a v a 2 s. co m } RandomCode = randomCode.toString(); return RandomCode.toLowerCase(); } }