Here you can find the source of getRandomString(int len)
Parameter | Description |
---|---|
len | Length of the random string |
public static String getRandomString(int len)
//package com.java2s; import java.util.*; public class Main { /** List of characters to use in random string generator */ private static final String RANDOM_CHARACTERS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; /**//from www .j av a2 s .c o m * Generate a string of random characters of the given length. * * @param len Length of the random string * @return String of random characters */ public static String getRandomString(int len) { Random rnd = new Random(); StringBuilder sb = new StringBuilder(len); for (int i = 0; i < len; i++) { sb.append(RANDOM_CHARACTERS.charAt(rnd.nextInt(RANDOM_CHARACTERS.length()))); } return sb.toString(); } }