Computer Science Canada Dice rolling... |
Author: | Squirter [ Mon Jan 26, 2004 6:39 pm ] | ||
Post subject: | Dice rolling... | ||
I'm trying to generate a number for a 20-sided die being rolled a certain amount of times.
Problem is, I want it to make a random number for each roll. Right now, it only gets one number, and multiplies it by the number of rolls I requested. e.g Set to roll 3 times. First it rolls a 4. But then it multiplies itself by 3. 4 * 3 = 12. I want it to make a different number each time, so: Set to roll 3 times. 5 + 17 +12 = 34. Anyone know the problem? (BTW, I'm pretty new to PHP, so if you put in a new command, could you explain it? ^^ |
Author: | octopi [ Mon Jan 26, 2004 8:27 pm ] | ||
Post subject: | |||
I think you want to roll the dice, the number of times specifiyed by 'rolls' consider the following:
the 'for' command loops the number threw the stuff in the {}'s the number of times specified by the '$x=1;$x <= $rolls; $x+=1', this says....the first time we enter the for loop, set x=1, then the next parts the condition, it keeps looping until this is false, and the next parts the counter, this increments x by 1, each time, until it meets the condition. |
Author: | Squirter [ Tue Jan 27, 2004 10:05 pm ] |
Post subject: | |
Er, I didn't really understand that... Could you give me another example? BTW, what is <=? |
Author: | PaddyLong [ Wed Jan 28, 2004 3:17 pm ] |
Post subject: | |
<= is just less than or equal to... same as in any boolean comparison expression in any language |
Author: | wtd [ Sat Feb 14, 2004 12:13 am ] | ||
Post subject: | |||
Just for the sake of havng an OO solution.
|