In the keyboard event handler, start by generating a random number based on the totalFrames property of the box MovieClip.
Something like this:
var randFrame:int = Math.floor(Math.random() * box.totalFrames) + 1;
// ... in the spacebar case
The +1 thing is due to the timeline starting at 1 and not zero.
Might need some additional logic there to avoid an out of range error at the top end of the scale.