File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Regarding random number generation. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Regarding random number generation." Watch "Regarding random number generation." New topic
Author

Regarding random number generation.

srinivas m
Greenhorn

Joined: Aug 06, 2004
Posts: 3
Hi,
I have this small doubt about generating random double values with in a range, for example between 0.6 to 1

I am new to java programming. Can any one help me on this.

Thanks in advance.

Nick George
Ranch Hand

Joined: Apr 04, 2004
Posts: 815
Math.random() returns a random double between 0 and 1. But you want a range of 0.4. Therefore, multiply Math.random() by .4. This gives you a random number between 0 and .4. Now add .6 to this number, pushing the range up to .6 to 1.

Dig?

-Joe


I've heard it takes forever to grow a woman from the ground
srinivas m
Greenhorn

Joined: Aug 06, 2004
Posts: 3
Thank you Joe,

That was too silly a question to ask.
Thank you again for bearing this topic.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regarding random number generation.