Here you can find the source of getRandomString(String paramString, int paramLength)
Parameter | Description |
---|---|
paramString | String from the Random string created |
paramLength | length of random string created |
public static String getRandomString(String paramString, int paramLength)
//package com.java2s; //License from project: Apache License import java.util.Random; public class Main { /**// w w w. ja v a2s .co m * Generate Random String * @param paramString String from the Random string created * @param paramLength length of random string created * @return random string containing character from above paramString of length paramLength */ public static String getRandomString(String paramString, int paramLength) { if (paramLength < 1) { throw new IllegalArgumentException("paramLength must be positive"); } StringBuilder stringBuilder = new StringBuilder(paramLength); Random random = new Random(); for (int j = 0; j < paramLength; j++) { stringBuilder.append(paramString.charAt(random.nextInt(paramString.length()))); } return stringBuilder.toString(); } }