Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

random function  RSS feed

 
Anthony Smith
Ranch Hand
Posts: 285
  • 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
  • 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
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!