aspose file tools*
The moose likes Beginning Java and the fly likes Random  number problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Random  number problem" Watch "Random  number problem" New topic
Author

Random number problem

Terence hiu
Ranch Hand

Joined: Oct 21, 2012
Posts: 36
Hi, is there a way of generating a random number of type double from -500 to 500 using the import random class?
Steve Fahlbusch
Bartender

Joined: Sep 18, 2000
Posts: 570
    
    7

Greetings,

assuming you are using java 7 (if not change 7 to the version you are using) and google 'java Random api 7'.

After reading the API you should find that......

First of all the class is java.util.Random.

Second there is a method that will return a type you want, but the range needs to be changed.

And how do you change a numeric range? Well to make the range wider or small you could multiply by some factor.

And to change the base (i.e.: the lowest part of the range) to some number you could add (or subtract) some number.

Hope this helps

-steve

Oh by the way, the answer to the question you asked was a simple - yes.

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39380
    
  28
If you use java.util.Random, you have a method which makes that whole procedure simpler.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Random number problem