Java Random String getRandomString(int length)

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

Description

get Random String

License

Open Source License

Declaration

public static String getRandomString(int length) 

Method Source Code

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

import java.util.Random;

public class Main {
    public static String getRandomString(int length) {
        char[] chars = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
        Random random = new Random();
        StringBuilder stringBuiler = new StringBuilder();
        for (int i = 0; i < length; i++) {
            stringBuiler.append(chars[Math.abs(random.nextInt()) % 16]);
        }//from  ww w  .  j av a  2  s  .c  o m
        return stringBuiler.toString();
    }
}

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)