| 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
Ranch Hand
Joined: Sep 18, 2000
Posts: 491
|
|
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: 32607
|
|
|
If you use java.util.Random, you have a method which makes that whole procedure simpler.
|
 |
 |
|
|
subject: Random number problem
|
|
|