File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes random function 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 » Beginning Java
Bookmark "random function" Watch "random function" New topic
Author

random function

Anthony Smith
Ranch Hand

Joined: Sep 10, 2001
Posts: 285
double x = Math.random()*9;
return (int)x;
WHy am I getting a possible loss of precison error? What are my choices?
Tom Ben
Ranch Hand

Joined: Aug 17, 2001
Posts: 109
I tried this and never got an error. Can you display the rest of the code in how you are using it?
This is how I am using it
public static void main(String args[]) {
System.out.println(ran());
}
static int ran() {
double x = Math.random()*9;
return (int)x;
}
Hope this maybe helps.
Originally posted by Anthony Smith:
double x = Math.random()*9;
return (int)x;
WHy am I getting a possible loss of precison error? What are my choices?


------------------
Sun Certified Programmer on the Java 2 Platform


Sun Certified Programmer on the Java 2 Platform
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: random function