Java random number generator
15,554
You can always generate individual digits of the number randomly. This way for a 15 digit number you can generate 15 digits randomly and then form the number.
Another way:
Lets change the problem to generate random 5 digit number.
Min = 10000
Max = 99999
Now generate a random number between 0
and Max - Min
which is 0
and 89999
and add it to Min
.
Random = Min + Math.random() * (Max - Min)
Author by
Ryan Sayles
Updated on June 15, 2022Comments
-
Ryan Sayles almost 2 years
Is it possible to have a user choose the number of digits of a random number, specifically a random Big Integer? For example if the user wants it to be 15 digits long the random number generator would only produce 15 digit long Big Integers.