Java Random String getRandomString(int length)

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

Description

get Random String

License

Open Source License

Parameter

Parameter Description
length a parameter

Declaration

public static String getRandomString(int length) 

Method Source Code

//package com.java2s;

import java.util.Random;

public class Main {

    public static String getRandomString(int length) {
        String RandomCode = "";
        char[] codeSequence = { '3', '4', '5', '6', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
                'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6',
                '7', '8', '9' };
        Random random = new Random();
        StringBuffer randomCode = new StringBuffer();
        for (int i = 0; i < length; i++) {
            String strRand = String.valueOf(codeSequence[random.nextInt(40)]);
            randomCode.append(strRand);//from w ww  .  j  a  v  a 2  s.  co m
        }
        RandomCode = randomCode.toString();
        return RandomCode.toLowerCase();
    }
}

Related

  1. getRandomString(int length)
  2. getRandomString(int length)
  3. getRandomString(int length)
  4. getRandomString(int length)
  5. getRandomString(int length)
  6. getRandomString(int length, Random rnd)
  7. getRandomString(int length, String charset)
  8. getRandomString(int min, int max)
  9. getRandomString(int minLength, int maxLength)