Java BigInteger create random String
import java.math.BigInteger; import java.security.SecureRandom; import java.util.Random; public class Main { public static void main(String[] args) { System.out.println(randomKey(5)); System.out.println(randomKey(10)); }/*w w w. j a v a 2s . c om*/ static final Random random = new SecureRandom(); public static String randomKey(int length) { return String.format("%"+length+"s", new BigInteger(length*5/*base 32,2^5*/, random) .toString(32)).replace('\u0020', '0'); } }