Java Random String getRandomString(int length)

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

Description

get Random String

License

Apache License

Declaration

public static String getRandomString(int length) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Random;

public class Main {
    public static String getRandomString(int length) {
        Random r = new Random();
        char min = 48;
        char max = 122;
        String ranStr = "";
        for (int i = 0; i < length; i++) {
            char c = (char) (r.nextInt(max - min + 1) + min);
            ranStr += c;/*from w w  w  .j a va  2s .co  m*/
        }

        return ranStr;
    }
}

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)
  7. getRandomString(int length)
  8. getRandomString(int length)
  9. getRandomString(int length)