Different Use of random() in Videos vs. Magic 8 Ball Project
I've done several evaluations for the Magic 8 Ball project. I noticed that people seemed to be having trouble figuring out the range of values to expect from the call to random().
I believe that this is largely due to the fact that random() is never fully explained. Its use is demonstrated in one of the videos. But when it's used to produce (pseudo)random integers, the person in the video uses round(). So the example integer = round(random(1, 3)); produces values between 1 and 3 inclusive. However, when given the Magic 8 Ball Project immediately after this, the example code uses floor().
floor() is never introduced or explained anywhere. Neither is random() for that matter, beyond the fact that it will return random numbers between the two values passed to it. But the fact that it is between arg1 and arg2 exclusive (rather than inclusive) is never actually mentioned. I only know this because I have some previous experience with programming.
So, floor(random(1,5)) will return integer values between 1 and 4, not 1 and 5. But, since random() has never been fully explained and floor() has never even been mentioned, a lot of people working on this project assume that the values produced will include 5.
If floor() and random() aren't going to be fully explained and introduced before the Magic 8 Ball project, then I think it would make more sense to use round() in the example code to remain consistent with what students have already seen.
Please sign in to leave a comment.