V
V
Vadim Pirx2016-05-26 20:35:42
Java
Vadim Pirx, 2016-05-26 20:35:42

How to generate a 14 digit positive number?

How to generate a 14 digit positive number?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Marat, 2016-05-26
@pirxon

If you need long ones (let's say 100-digit ones), then it can be costly like this (example for 14-digit ones):

BigInteger b;
do{
       b = new BigInteger(48, new SecureRandom());
} while (b.toString().length()!=14);
System.out.println(b.toString());

V
Vadim Pirx, 2016-05-27
@pirxon

thank. both options are good.

T
Timur, 2016-05-29
@timych

Here's another option:

ThreadLocalRandom.current().nextLong(10000000000000L, 100000000000000L);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question