Here you can find the source of getRandomString(final int length)
Parameter | Description |
---|---|
length | the length of the string |
public static String getRandomString(final int length)
//package com.java2s; //License from project: Open Source License import java.util.Random; public class Main { /**/*from w w w .j a va 2s . c om*/ * returns a random string of characters (A-Z) of the specified length * * @param length the length of the string * @return random string * */ public static String getRandomString(final int length) { final StringBuffer sb = new StringBuffer(); final Random rand = new Random(); for (int i = 0; i < length; i++) sb.append((char) ((Math.abs(rand.nextInt()) % 26) + 65)); return sb.toString(); } }