Welcome to JavaRanch!
Well, java.util.Random has a method nextDouble() which returns a number between 0.0 and 1.0 . You can use that, applying simple arithmetic to change the range of the value. If you have trouble, show us what you've done so far and we can tell you where any problems might lie.
If you care about the exact boundaries, there might be a problem. Math.random() gives a number greater than or equal to 0.0 and less than 1.0. So Math.random() - 0.5 gives a number great than or equal to -0.5 and less than 0.5. Is that close enough, for your application?
Note that Java programmers usually use the java.util.Random class, rather than Math.random() method. To understand why, read the Java API documentation on both.
[ September 11, 2006: Message edited by: Peter Chase ]
Originally posted by makhan gee:
I want to generate random numbers from -0.5 to 0.5 using Math.random().
Thankzzzz in advance.
Although your name policy doesn't match with Rancher's Names Policy.
I request to Moderators to notice that..
[ EJFH: Deleted code; this is clearly homework, let the guy do his own work, please. ]
[ September 11, 2006: Message edited by: Ernest Friedman-Hill ]
Originally posted by Ernest Friedman-Hill:
Can you tell us why? Sounds fine to me, but of course I don't speak any Indian languages.
Yes Offcourse I can tell you, why it is not a valid name.
Makhan -- Butter
Gee or Ghee -- Fat
These are the words used in Hindi very often(Indian Language).
I hope now you are clear on the name of makhan gee