Math.Random() - Java question

Started by
6 comments, last by DribbleDribble 13 years, 6 months ago
Hello everyone, I have a quick question that Im assuming isnt to complex.

I am needing to generaterandom numbers from between 1 - 60, and 1- 100, and 1-20.

I was wondering if someone could possibly explain how to do so for me.

Thanks in advance!
Advertisement
Take a look at the java.util.Random class ;)
I did, still having troubles :/
But I think I may have figured it out.
Quote:Original post by DribbleDribble
I did, still having troubles :/
But I think I may have figured it out.


Random rand = new Random();int i = rand.nextInt(60)+1; // 1 to 60int i = rand.nextInt(100)+1; // 1 to 100int i = rand.nextInt(20)+1; // 1 to 20
Thanks much, that helped alot!
But for some odd reason, Im running into a problem, but I dont think it has to do with an error in the code.

Whats happend is that this program is supposed to calculate randomly, the grades of students (the amount the user inputs). It does that, but it only ever generates F's, maybe an occasional D.
So the output is basically supposed to be like:

Student 1 got (random) on assignment 1
(random) on assignment 2
(random) on assignment 3
Etc

Students has passed/failed the class with (A,B,C,D, or F)

But its only generating scores high enough for Fs, and maybe an occasional D.

Any suggestions?
Post your code and we can tell you why that is, otherwise we have to guess or try and read your mind from across the internets!
Sorry, completely understand.

I will in about a day or so. Its part of an assignment, and its do in 5 minutes. But the reason Ill post it later is because I did once, and it got me into trouble cause another kid in my class coppied my code.

But its still something I need to learn, so I will post it sometime soon.

This topic is closed to new replies.

Advertisement