Java Random String GetRandomStr(int length)

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

Description

Get Random Str

License

Apache License

Declaration

public static String GetRandomStr(int length) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.Random;

public class Main {
    private final static String chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

    public static String GetRandomStr(int length) {
        Random rnd = new Random(System.currentTimeMillis());
        StringBuffer buf = new StringBuffer();
        for (int i = 0; i < length; i++) {
            int val = rnd.nextInt(chars.length());
            buf.append(chars.charAt(val));
        }// w ww. j a  v  a  2  s .  c  o m
        return buf.toString();
    }
}

Related

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