Here - 1000 BiT

Here - 1000 BiT Here - 1000 BiT

11.07.2015 Views

uINSTRUCTOR NOTES 13 RANDOM NUMBERS AND THE INT FUNCTION uThis lesson introduces two functions: RND and INT. These are very important in gamesand also handy in making interesting displays like kaleidoscopes.The RND function produces psuedo-random decimal numbers larger than 0 and smallerthan 1. Such numbers are directly usable as probabilities, but integers over some range ^Jsuch as 1 to 6 for a die, or 1 to 13 for a suit of cards are often more directly usable.Your student may be shaky in decimal arithmetic, but all that is required here is ,multiplication of the random number by an integer, and perhaps also addition to aninteger. The computer does the multiplication, of course, so only a rough idea of the ^jdesired result is necessary.After extending the random number to a larger range than 0 to 1, conversion to aninteger is desired. The INT function does this by simply truncating the number, "throwing ^away the decimal part." (For negative numbers the situation is a little more complicated, *>and that rare case is not treated here.)The concept of "rounding off' may be familiar to your student. INT will round off anumber if you first add 0.5 to it.

LESSON 13RANDOM NUMBERS AND THE INT FUNCTIONTHE RND FUNCTIONWhen you throw dice, you can't predict what numbers will come up.When dealing cards, you can't predict what cards each person will get.You need some way to "roll dice" and "deal cards" and do other unpredictable thingswith the computer.Use the RND function to do this. RND stands for "random."Run this program:10REM RANDOM NUMBERS20 PRINT "clrdndn"25 LETN=RND(8)30 PRINT N40 IF N

LESSON 13RANDOM NUMBERS AND THE INT FUNCTIONTHE RND FUNCTIONWhen you throw dice, you can't predict what numbers will come up.When dealing cards, you can't predict what cards each person will get.You need some way to "roll dice" and "deal cards" and do other unpredictable thingswith the computer.Use the RND function to do this. RND stands for "random."Run this program:10REM RANDOM NUMBERS20 PRINT "clrdndn"25 LETN=RND(8)30 PRINT N40 IF N

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!