• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to choose a random no in a specific range?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks argm Mastoi
i was puzzeld before ur reply thank u

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic