aspose file tools*
The moose likes Beginning Java and the fly likes How to choose a random no in a specific range? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to choose a random no in a specific range?" Watch "How to choose a random no in a specific range?" New topic
Author

How to choose a random no in a specific range?

aarijmh
Greenhorn

Joined: Oct 31, 2001
Posts: 2
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

Joined: Oct 16, 2001
Posts: 35
check this link, the whole discussion is there:
http://www.javaranch.com/ubb/Forum33/HTML/003787.html
Argm Mastoi
Ranch Hand

Joined: Oct 16, 2001
Posts: 35
for an easy way u can try this out:
int h= ((int)Math.random*50+1);
System.out.println(h);
aarijmh
Greenhorn

Joined: Oct 31, 2001
Posts: 2
thanks argm Mastoi
i was puzzeld before ur reply thank u

Khurram Akhter
Greenhorn

Joined: Oct 08, 2001
Posts: 3
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

Joined: May 10, 2001
Posts: 3244
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


Dave
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to choose a random no in a specific range?