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.*;

public class Main {
    private static final Random random = new Random();

    public static String generateRandomString(int length) {
        char[] characters = new char[length];
        for (int i = 0; i < length; i++) {
            char start, end;
            switch (random.nextInt(4)) {
            case 0:
                start = 'A';
                end = 'Z';
            case 1:
                start = '0';
                end = '9';
            default:
                start = 'a';
                end = 'z';
            }//from w ww .j a v  a  2s. c o  m
            characters[i] = (char) (start + random.nextInt(end - start));
        }
        return new String(characters);
    }
}

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)
  8. generateRandomString(int length)
  9. generateRandomString(int Length, String caseType)