This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to choose a random no in a specific range?

 
aarijmh
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pls help me out
i want to choose a random no b/w 1 and 50 how can i do it
 
Argm Mastoi
Ranch Hand
Posts: 35
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
check this link, the whole discussion is there:
http://www.javaranch.com/ubb/Forum33/HTML/003787.html
 
Argm Mastoi
Ranch Hand
Posts: 35
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for an easy way u can try this out:
int h= ((int)Math.random*50+1);
System.out.println(h);
 
aarijmh
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks argm Mastoi
i was puzzeld before ur reply thank u

 
Khurram Akhter
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want ot generate Random Numbers from 1 to 50 so,
you should write in a way
Starting No+Math.random()*Difference
for e.g,
int i = (int)(1+Math.random()*50);
system.out.println("Random Numbers are"+i);

so, the numbers are generated Randomly
:P
 
Dave Vick
Ranch Hand
Posts: 3244
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
aarijmh
Welcome to the Java Ranch, we hope you�ll enjoy visiting as a regular, however your name is not in keeping with naming policy
the here at the ranch. Please re-register under an appropriate name as shown in the policy.
Thanks again and we hope to see you around the ranch!!


------------------
Dave
Sun Certified Programmer for the Java� 2 Platform
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic