You can do this using an 'if' statement and the modulus operator:

if (frame % 5 == 0)

XXX.tx = rand(-1,1);

The modulus operator calculates the remainder of the division of the frame number by five. Only when the frame count is a multiple of five will this remainder be equal to zero. When that happens, the conditional statement executes, and the object is assigned a new position.

-Steve