The above code defines a new function I've chosen to call RandInt. When used, it expects to be given a number that I've called up_to. The function then calculates a random integer between zero and 'up_to' (whatever value it happens to have at that time), and stores it in another variable which I've called 'n'. The last line tells the function to return the value of 'n' as the result.
With that function now defined, I can use it like so:
I could have added one, and made it between 1 and 50, but for reasons that will soon becomes apparent, doing it this way will suit our purpose better.
|