Java Random String generateRandomString(int size)

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

Description

generate Random String

License

Open Source License

Declaration

public static String generateRandomString(int size) 

Method Source Code

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

import java.util.Random;

public class Main {
    private static String random_str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

    public static String generateRandomString(int size) {
        String random = new String();
        Random rand = new Random();

        for (int i = 0; i < size; i++) {
            int random_nbr = rand.nextInt(random_str.length());
            random += (rand.nextBoolean()) ? random_str.charAt(random_nbr)
                    : Character.toLowerCase(random.charAt(random_nbr));
        }//from  ww w  .j  a v a 2 s. c  om

        return random;
    }
}

Related

  1. generateRandomString(int Length, String caseType)
  2. generateRandomString(int length, String charset)
  3. generateRandomString(int minLength, int maxLength, int minLCaseCount, int minUCaseCount, int minNumCount, int minSpecialCount)
  4. generateRandomString(int n)
  5. generateRandomString(int n)
  6. generateRandomString(int stringLength)
  7. generateRandomString(int wordsLength, String separator)
  8. generateRandomString(Random random, int length)
  9. generateRandomString(Random random, int size)