Computer Science Canada

Program help?

Author:  abogaida [ Wed Apr 08, 2009 3:02 pm ]
Post subject:  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.

Author:  jbking [ Wed Apr 08, 2009 3:25 pm ]
Post subject:  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

Author:  matt271 [ Wed Apr 08, 2009 3:45 pm ]
Post subject:  Re: Program help?

this will give u a random number between 0 and 1 (non-include)

Java:
double x = Math.random();


if you want a random integer between 0 and 10 do this

Java:
int x = (int)11*Math.random();


or a random integer between 15 and 30:

Java:
int x = 15 + (int)16*Math.random();


its 11 and 16 not 10 and 15 because (int)10.99999999999999999999999999 = 10

Author:  abogaida [ Wed Apr 08, 2009 4:44 pm ]
Post subject:  RE:Program help?

Thanks a lot guys!


: