![]() |
| ||
| Clarity... hi just have a question to make sure i understand it. i'm doing the exercises in my book and it says i should create a program which will roll 2 dice and produce a random number then adds the sum of the outcomes. public class RollDicenow this is all okay but when i remove the +1 there isnt any difference. i just want to know if removing the +1 will cause any problem on the program. if not...how about if i'm writing a longer program, will there be any implication?Thanks |
| ||
| Re: Clarity... if take out +1 this will generate numbers in the interval between 0-5 inclusive |
| ||
| Re: Clarity... Thanks. |
| ||
| Re: Clarity... Yeh, thats right, to be precise... Math.random() generates a number between 0 and 1 inclusive, the chance of getting 0 or 1 is almost 0 though. so suppose you wanted 1 to 6, first you mulitply by 6, this gives you a number in the range 0-6, eg 5.92367236746. Then converting to an int, will always give you either 0,1,2,3,4,5. So just add 1, to get 1 to 6. |
| ||
| Re: Clarity... Thanks guys. And might i add...you guys post replies quite fast! cool! |
| All times are GMT -4. The time now is 6:44 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC