Date: Tuesday, 08 April 2008 12:33 PM From: Mark Jacobson To: 810-088-09-spring@uni.edu Subject: Quiz tommorrow... Wednesday Hi Flash students, Reminder: Quiz 5 will be tommorrow. The study guide for quiz #5 will be the same study guide that was used for quiz #4. http://www.cs.uni.edu/~jacobson/flash/quiz4.txt Math.floor() and Math.random() are the two functions we reviewed extensively yesterday when we went over quiz #4. Here is the code we used last Friday to make the racing rectangles: r1.x += Math.random() * 12; <--- Version without using r2.x += Math.random() * 12; Array approach was r3.x += Math.random() * 12; done first. r4.x += Math.random() * 12; for (var i:int = 0; i < 4; i++) { <--- Array version r[i].x += Math.random() * 21; was done last. } Note how both use Math.random() function and multiply by 12 or by 21. Of course, the 2nd version had to store the rectangle objects in the array first with the following four statements. r[0] = r1; r[1] = r2; r[2] = r3; r[3] = r4; ------------ What if we did the following instead: (Use the Math.floor() function). ------------ r1.x += Math.floor( Math.random() * 12 ); for (var i:int = 0; i < 4; i++) { r[i].x += Math.floor( Math.random() * 21 ); } http://www.uni.edu/jacobson/rectangleRace.html Using the Math.floor() function would cause no difference is how the racing rectangles movie appeared to the user. Math.random() * 21 gives numbers like 1.593 and 19.2167 and 0.44821 whereas Math.floor( Math.random() * 21 ) gives only these numbers: 0, 1, 2, 3, 4, 5, ..., 18, 19, 20 There are only 21 different outputs possible for Math.floor( Math.random() * 21 ) whereas there are millions or billions of possible outputs for Math.random() * 21 i.e. 1.563127 and 1.563128 are different outputs or results. 1.0000001 is different from 1.0000002 The take home quiz/assignment that was to be due tommorrow will be due on Friday instead of being due tommorrow. http://www.cs.uni.edu/~jacobson/flash Mark