Game Development Reference
be part of the range, however, use I]pd*nkqj` instead. I]pd*nkqj`$I]pd*n]j`ki$%&-,,% will give
you a random number between 0 and 100.
What if you want to generate a random number within a range of numbers that starts
at something other than 1 or zero?
Let's say you need a number between 10 and 25. That means that you have 15 possible
numbers that could be chosen: 10, 11, 12 . . . up to 25. All you need to do is generate
a random number between 0 and 15, and then add 10 to it push it up to within the
range you need. This is what the code will look like:
Think about it this way. The random number is between 0 and 15. Let's say it's 8. Then
you add 10 to it. You end up with 18. You've got a range of possible random numbers
between 10 and 25!
Now use what you learned about random numbers and apply it to the game:
1. Modify the ejep method with the new code in bold. In addition to randomizing the
iuopanuJqi^an variable, you've added a pn]_a directive for testing purposes so that you can
actually see what that number is in the Output panel. (Notice that string concatenation was
used in the pn]_a directive so that the display in the Output panel is more readable.)