Sign in to follow this  
DribbleDribble

Math.Random() - Java question

Recommended Posts

DribbleDribble    100
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!

Share this post


Link to post
Share on other sites
Rene Z    605
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 60
int i = rand.nextInt(100)+1; // 1 to 100
int i = rand.nextInt(20)+1; // 1 to 20

Share this post


Link to post
Share on other sites
DribbleDribble    100
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.

Share this post


Link to post
Share on other sites
DribbleDribble    100
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?

Share this post


Link to post
Share on other sites
DribbleDribble    100
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this