Java ThreadLocalRandom RandomString(int length)

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

Description

Random String

License

Open Source License

Declaration

public static String RandomString(int length) 

Method Source Code

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

import java.util.concurrent.ThreadLocalRandom;

public class Main {

    public static String RandomString(int length) {
        String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        //        Random random = new Random();
        StringBuffer buf = new StringBuffer();
        for (int i = 0; i < length; i++) {
            //            int num = random.nextInt(62);
            int num = ThreadLocalRandom.current().nextInt(62);
            buf.append(str.charAt(num));
        }/*w ww  . ja v  a 2s.c  o  m*/
        return buf.toString();
    }
}

Related

  1. randomNums(int min, int max, int count)
  2. randomPer(long num, long divisor)
  3. randomReal(float range)
  4. randomSeed()
  5. randomString()
  6. randomString(int minLength, int maxLength)
  7. randomString(List strings)
  8. randomStringArray(int arrayLength, int stringLength)
  9. randomWorld()