Java Random String getRandomStr(int length)

Here you can find the source of getRandomStr(int length)

Description

get Random Str

License

LGPL

Declaration

public static String getRandomStr(int length) 

Method Source Code

//package com.java2s;

import java.util.Random;

public class Main {
    private static final StringBuffer characters = new StringBuffer(
            "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");

    public static String getRandomStr(int length) {

        StringBuffer sbf = new StringBuffer();
        Random rand = new Random();
        int charSize = characters.length();
        for (int i = 0; i < length; i++) {
            sbf.append(characters.charAt(rand.nextInt(charSize)));
        }/*  w ww . jav a 2s. c  om*/

        return sbf.toString();
    }
}

Related

  1. getrandomstr()
  2. getRandomStr()
  3. getRandomStr(int Len)
  4. getRandomStr(int length)
  5. GetRandomStr(int length)
  6. getRandomStr(int n)
  7. getRandomStr(int qty)
  8. getRandomStr(String src)
  9. getRandomString()