• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

random doubt

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

Found this on Phil & Simon Book.



Answer's provided
1. 2
2. 3
3. Impossible to say.

Answer given 3.

I was wondering since random() returs values >= 0.0 - < 1.0.
Least value is 0.0 - Math.round( 2.50001 ) -> 3
Max Value is 0.9 - Math.round( 3.40001 ) -> 3

Can the random() values returned go more than one decimal like 0.9999 (then how far). I know that would change the value. I checked java doc on random() there too he does not mention on the decimal part of it.

Please clarify.

- Kits
[ August 25, 2004: Message edited by: Barry Gaunt ]
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's a little program to show how close to 1.0 you can get using a double


Bear in mind that all this is only approximate and that the System.out.println method also adds to the confusion by doing tricks to format the internal floating point register contents into human readable output.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic