2

javaで16桁の乱数を作りたいです。私は String でそれを行うことができ、その後 Long に変換します。他のオプションはありますか?

ありがとう!

4

3 に答える 3

4

絶対に16桁が必要な場合(0から10 ^ 17-1の数字ではありません)

Random rand = new Random;
long accumulator = 1 + rand.nextInt(9); // ensures that the 16th digit isn't 0
for(int i = 0; i < 15; i++) {
    accumulator *= 10L;
    accumulator += rand.nextint(10);
}

i < 16必要に応じて使用してください。

于 2013-04-17T17:54:44.613 に答える