Here you can find the source of getRandomString(int length)
public static String getRandomString(int length)
//package com.java2s; /**/*w ww . j ava 2 s .c om*/ * Copyright (c) 2014 http://www.lushapp.wang * * Licensed under the Apache License, Version 2.0 (the "License"); */ import java.util.*; public class Main { public static String getRandomString(int length) { StringBuffer bu = new StringBuffer(); String[] arr = { "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "m", "n", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" }; Random random = new Random(); while (bu.length() < length) { String temp = arr[random.nextInt(57)]; if (bu.indexOf(temp) == -1) { bu.append(temp); } } return bu.toString(); } }