Program the Rover to act like a bug and move around randomly looking for food. Use the random-number math block to generate a speed for each motor, this creates a randomly moving bug Rover.
Setup
Random number generation will have the Rover move around unpredictably. Depending on the ranges students use, the random numbers may send the Rover a long way. Set the speeds and durations to suit the space you have, and keep an eye on the Rovers while they drive.
Our Approach
Stage 1: Random Motor Speeds
Start with an advanced motor block that sets different speeds for the left and right motors. Inside each slot, use the Random Integer block from the Math category. We use the range −15 to 15, negative values send the motor backwards. The block has a chance of setting either motor forward or backward.
Stage 2: Random Duration
Control how long the Rover runs at each speed using a Delay block. To keep things unpredictable, use another Random Integer block to set the delay to between 1 and 3 seconds.
Stage 3: Loop Forever
Wrap everything in a While True loop so the Rover picks new random speeds each cycle.

Example code, random-speed bug Rover
Continue Learning
Related resourceActivity: Roaming RoverLearn to avoid obstacles with the ultrasonic sensor.


