Java Random String generateRandomString(int length)

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

Description

generate Random String

License

Open Source License

Declaration

public static String generateRandomString(int length) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Random;

public class Main {
    public static String generateRandomString(int length) {
        String base = "abcdefghijklmnopqrstuvwxyz0123456789";
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < length; i++) {
            int number = random.nextInt(base.length());
            sb.append(base.charAt(number));
        }/*from   w  w w  . j  a va2  s .  c o m*/
        return sb.toString();
    }
}

Related

  1. generateRandomString(int length)
  2. generateRandomString(int length)
  3. generateRandomString(int length)
  4. generateRandomString(int length)
  5. generateRandomString(int length)
  6. generateRandomString(int length)
  7. generateRandomString(int Length, String caseType)
  8. generateRandomString(int length, String charset)
  9. generateRandomString(int minLength, int maxLength, int minLCaseCount, int minUCaseCount, int minNumCount, int minSpecialCount)