BigInteger b;
do{
b = new BigInteger(48, new SecureRandom());
} while (b.toString().length()!=14);
System.out.println(b.toString());
public static BigInteger generateBigInteger(int length, Random random) {
StringBuilder builder = new StringBuilder(length);
builder.append(random.nextInt(9) + 1);
for (int i = 1; i < length; i++) {
builder.append(random.nextInt(10));
}
return new BigInteger(builder.toString());
}
ThreadLocalRandom.current().nextLong(10000000000000L, 100000000000000L);
Find more questions by tags Java
1) And if you need 500 digits? Then just change the 48 to a different value.
2) int allows you to generate a 19 digit (if the least significant 63 bits).
For the 14 digit enough
- darron.Wunsch commented on July 9th 19 at 11:28