Java ThreadLocalRandom getRandomPassword()

Here you can find the source of getRandomPassword()

Description

get Random Password

License

Apache License

Declaration

public static String getRandomPassword() 

Method Source Code


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

import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;

public class Main {
    private static char[] chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()"
            .toCharArray();//from   ww w  .ja  v a 2s.c om

    public static String getRandomPassword() {
        Random random = ThreadLocalRandom.current();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < 5 + random.nextInt(15); i++) {
            char c = chars[random.nextInt(chars.length)];
            sb.append(c);
        }
        return sb.toString();
    }
}

Related

  1. getRandomInt(int n)
  2. getRandomInt(int r)
  3. getRandomInteger()
  4. getRandomIntegerElement(List list)
  5. getRandomNumbers(Integer startNumber, Integer endNumber, Integer pageSize, Integer numNumbers)
  6. getRandomStr(int len)
  7. getRandomString(int length)
  8. getRandomTarget(List targets)
  9. getRandomValue(String prefix, long maxValue)