Advanced Ev3 Programming Lesson: Random Block
Advanced Ev3 Programming Lesson: Random Block
EV3
PROGRAMMING LESSON
Random Block
By Sanjay and Arvind Seshan
Lesson Objectives
ì Making a Game
ì In a loop, record how many times you get each number using
three variables
ì What do you notice about the number of times you got #1 vs.
#2 vs. #3?
Get random
Three variables – one Wait before
number
for each number exiting
ì You will notice that you got the #1 and #3 about 250 times each.
But you got the #2 around 500 times
ì This is due to a bug in the EV3 that causes the boundary values
(1 and 3 in our example) to occur half as often as the middle
values (2 in our example). This is true no matter what your
range of numbers is.
ì Can you think of how you might fix this problem to get a better
random number?
ì Record how many times you get each number and compare the
results to the previous results
Add and Subtract 1 from the range Get random value If random is a boundary value -> repeat