
-----------------------------------
abogaida
Wed Apr 08, 2009 3:02 pm

Program help?
-----------------------------------
I am new in java. I just finished my first course in it. I was thinking of making this program about a little game that when I was young my parents used to play with us. The game is about math mathematics. Not to bore you with the details, I was wondering how can make a program to select a random integer number.

-----------------------------------
jbking
Wed Apr 08, 2009 3:25 pm

Re: Program help?
-----------------------------------
Have you looked at any of the following resources about Java's built in Random class and methods?

http://www.javapractices.com/topic/TopicAction.do?Id=62
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Random.html
http://www.cs.geneseo.edu/~baldwin/reference/random.html

-----------------------------------
matt271
Wed Apr 08, 2009 3:45 pm

Re: Program help?
-----------------------------------
this will give u a random number between 0 and 1 (non-include)

double x = Math.random();

if you want a random integer between 0 and 10 do this

int x = (int)11*Math.random();

or a random integer between 15 and 30:

int x = 15 + (int)16*Math.random();

its 11 and 16 not 10 and 15 because (int)10.99999999999999999999999999 = 10

-----------------------------------
abogaida
Wed Apr 08, 2009 4:44 pm

RE:Program help?
-----------------------------------
Thanks a lot guys!
