Java Random String generateRandomString(int n)

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

Description

generate Random String

License

Open Source License

Declaration

public static String generateRandomString(int n) 

Method Source Code

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

import java.util.Random;

public class Main {
    public static String generateRandomString(int n) {
        String alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
        int length = alphabet.length();
        String s = "";
        Random r = new Random(System.currentTimeMillis());
        for (int i = 0; i < n; i++)
            s += alphabet.charAt(r.nextInt(length));
        return s;
    }/*from ww  w  .j av  a 2 s  .  c  o m*/
}

Related

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