someone can teach me about the random genrated?
let say i would like to generate a random number between 100 to 200 and store it into one integer variable, what is the code??????
v2_vehooi
0
Newbie Poster
Recommended Answers
Jump to PostI would suggest adding one to the end of the generated number or else you wont ever reach 200.
Jump to PostThe best way is to add one to the end. You don't need the round method; A better choice would be the Math.ceil() method since it rounds up.
int i=(int)(101+((int)100*Math.random()));or
int i=(int)(100+((int)101*Math.random()));or
int i=(int)(100+((int)100*Math.random()))+1; //My choice
All 5 Replies
cheenu78
0
Light Poster
lamak
0
Newbie Poster
server_crash
64
Postaholic
v2_vehooi
0
Newbie Poster
server_crash
64
Postaholic
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.