Random Number between 10 and 30

I'm just curious how to generate a random number between 10 and 30. I know I use the Math.Random function, but I'm not certain how to do it when the starting number is >1 (i.e. 1 to 30). Thanks.
[206 byte] By [Lava_Javaa] at [2007-11-27 5:24:43]
# 1
Use the Random class' nextInt(int) method. It returns an int between 0 inclusive and the number you specify exclusive. Use the range of your numbers as the parameter, and then add your minimum to the result.
hunter9000a at 2007-7-12 14:44:15 > top of Java-index,Java Essentials,New To Java...
# 2
17No need to thank me.
Hippolytea at 2007-7-12 14:44:15 > top of Java-index,Java Essentials,New To Java...
# 3
> 17> > No need to thank me.Something must be wrong with your RNG. I came up with 23. I know it's right because I can reproduce 23 every time.
KelVarnsona at 2007-7-12 14:44:16 > top of Java-index,Java Essentials,New To Java...
# 4
They are both prime, so that much is working fine.
Hippolytea at 2007-7-12 14:44:16 > top of Java-index,Java Essentials,New To Java...
# 5
[url #" style="display: block; background-image:url(' http://www.wiskundemeisjes.nl/wp-content/uploads/2006/12/randomdilbert.jpg'); width:500px; height:197px] [/url]
prometheuzza at 2007-7-12 14:44:16 > top of Java-index,Java Essentials,New To Java...
# 6

Random Number in an Interval:

((int) (randomGeneratedNumber * difference)) + startIndex + 1

* randomGeneratedNumber - Number >= 0 and <1

* difference: To generate between 10 and 30, (30 -10 = 20)

* startIndex: In this example, 10

* +1: Neccesary adjustment.

Example:

((int)(randomGeneratedNumber * 20)) + 10 + 1

PD. Int cast it's to generate int numbers, so it's optional.

totua at 2007-7-12 14:44:16 > top of Java-index,Java Essentials,New To Java...
# 7
[url #" style="display: block;background-image:url(' http://imgs.xkcd.com/comics/random_number.png');width:408px; height:152px] [/url]from [url= http://xkcd.com/]xkcd[/url]
TuringPesta at 2007-7-12 14:44:16 > top of Java-index,Java Essentials,New To Java...