Sign up, and you'll be able to customize your font size and more! Sign upIt appears that your browser timezone is different than what is currently being used. Do you want to switch to UTC? Change timezone
Jan 13, 2025
10:31:59pm
Cosmo Kramer All-American
If rand() returns a value between 0 and 1, mod 5 can be ignored.
The result of the calculation, that is the parameter of the random() method's return statement will contain a floating point value between 1 and 2 inclusive. Because the method random() returns an int, the compiler should give a warning, something about loss of precision, but that's not at issue here. The return value of random() will be an integer with the value of either 1 or 2. The problem you have is that you don't know what rounding function will be used, because a specific rounding function is not used. If the default rounding function is not floor or ceiling, the return value of the random() method will return 1 or 2 with equal probability. If this is true, simply subtract 1 from the return value of the random() method and go home for dinner. If the default rounding is floor or ceiling, order pizza and tell your wife it'll be another late night in the office.
This message has been modified
Originally posted on Jan 13, 2025 at 10:31:59pm
Message modified by Cosmo Kramer on Jan 13, 2025 at 10:37:00pm
Cosmo Kramer
Previous username
GoCougies
Bio page
Cosmo Kramer
Joined
Jul 29, 2005
Last login
Jan 14, 2025
Total posts
27,405 (1,406 FO)
Messages
Author
Time
Jan 13, 10:03pm
Jan 13, 10:03pm

Posting on CougarBoard

In order to post, you will need to either sign up or log in.