When the hunter has not found a mushroom recently, it turns a random angle between -45 and +45 degrees instead of between -10 and +10 degrees. What does the following NetLogo statement do? [right (random 21) - 10] Where does that statement occur in the original mushroom hunt model? Note: See your mushroom assignment #1 handout or see your NetLogo model code or see http://www.cs.uni.edu/~jacobson/1025/logo/room1.pdf for the scanned in handout. What does it do? [right (random 21) - 10] Break this down into 3 questions? 1. What does (random 21) do or create? ----------- 2. What does (random 21) - 10 do or result in? ---------------- 3. What does [right (random 21) - 10] do? ------------------------ random 21 <---- What does this mean? See the NetLogo Dictionary. Help menu NetLogo Dictionary command ... Go to and click on the MATH Category. It is the 13th of 18 different categories. Find and click on RANDOM. random random-exponential random-float random-gamma random-normal random-poisson random-seed Here is what you will see: ------ random ------ random number If number is positive, reports a random integer greater than or equal to 0, but strictly less than number. So our specific example code includes the following: random 21 where 21 is the number.... Since 21 is a positive number, random 21 reports a random integer greater than or equal to 0, but strictly less than 21. random 21 thus returns or results in one of the following integers: 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19, or 20 It returns exactly one of the first 21 non-negative integers. --------------------------- 2. What does (random 21) - 10 do or result in? ---------------- Now that we know (random 21) is an integer between 0 and 20 inclusive, its easy to see what subtracting 10 does. ( 0, 1, 2, ..., 19, 20) -10 -10 -10 -10 -10 --- --- --- --- --- ( -10, -9, -8, ..., 9 10) Now that we know what (random 21) - 10 results in, an integer that is greater than or equal to -10 and less than or equal to 10, the 3rd question is simple. 3. What does [right (random 21) - 10] do? ------------------------ Note that right is the same as rt, which we are more used to using during class. [rt (random 21) - 10] is how I would "write" it, but right is just as right as rt, right? So all this statement does is cause the turtle to turn to the right -10, -9, -8, ..., -1, 0, 1, 2, ..., 9, or 10 degrees. Actually, if the turtle turns to the right minus degrees, it is turning to the LEFT. rt -10 or right -10 would actually turn the turtle to the left 10 degrees. Example for throwing DICE for a dice game like Monopoly or Yahtzee. (random 6) returns the result 0, 1, 2, 3, 4 or 5. Adding 1 to this will be what is needed to simulate the die so we can roll the die or roll it twice to simulate a pair of dice. (random 6) + 1 returns the result 1, 2, 3, 4, 5 or 6 Question: How many INTEGERS are there between -45 and +45, including -45 and +45? Simpler problem: How many integers between -3 and +3, inclusive of -3 and +3? -3, -2, - 1, 3 0, +1 +1, +2, +3 +3 ---- 7 3 times 2 + 1 = 7 integers... How would you generate a random integer in this group of 7 integers? (random 7) - 3 gives you a -3, -2, -1, 0, 1, 2 or 3