I thought about using a loop and generating a random number inside it until the number is in the right range but is there a better way to do this?
Asked
Active
Viewed 44 times
-1
-
When unsure of whether some code is ideal for a given problem, posting the code on https://codereview.stackexchange.com would be the recommended option. – manish Apr 05 '18 at 06:50
-
1what have you tried ? where you stuck up, Show us some effort – Rishal Apr 05 '18 at 06:51
-
this question is duplicate: https://stackoverflow.com/questions/5271598/java-generate-random-number-between-two-given-values – Paplusc Apr 05 '18 at 06:52
1 Answers
1
You can use
new Random().nextInt(max- min) + min
to generate the number between ranges

Deb
- 2,922
- 1
- 16
- 32
-
Sorry if I'm misunderstanding, I'm a complete beginner. Wouldn't I have to generate a random number 'n' and then use Math.pow to get 10^n-1 or something along those lines? Could I plug 10^(n-1) and (10^n)-1 straight into the random generator? – Aesteria Apr 05 '18 at 07:00