Here you can find the source of getRandomString(int length)
Parameter | Description |
---|---|
length | a parameter |
public static String getRandomString(int length)
//package com.java2s; //License from project: Open Source License import java.util.Random; public class Main { /**/*from ww w. jav a 2s . c o m*/ * Generates a random string with the provided length. * * @param length * @return */ public static String getRandomString(int length) { StringBuffer retObj = new StringBuffer(); String letters = "abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ23456789"; Random random = new Random(System.currentTimeMillis()); for (int i = 0; i < length; i++) { int pos = random.nextInt(letters.length()); retObj.append(letters.charAt(pos)); } return retObj.toString(); } }