File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

random function

 
Anthony Smith
Ranch Hand
Posts: 285
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 109
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic