0

Trying to random an integer between 15-20, inclusive.

Am I implementing this code correctly?

    Random radiusChooser = new Random();
    radius = radiusChooser.nextInt(21)-6;
Nadal
  • 7
  • 5
  • 1
    radius = radiusChooser.nextInt(6) + 15; – Gilbert Le Blanc Apr 17 '14 at 00:31
  • Firstly, you can just print the numbers you are generating to check if it works. Secondly, when you typed in this question SO showed you many other questions asking this same thing. Please refer to those (or all the related questions on the right of your screen) first and if none of them help, then ask a new question here. – takendarkk Apr 17 '14 at 00:35

1 Answers1

0

Try this instead:

radius = radiusChooser.nextInt(6) + 15;

This will choose a random number between 0 and 5 (inclusive) and then add 15 to it - which gives you a random number between 15 and 20 (inclusive).

user253751
  • 57,427
  • 7
  • 48
  • 90