Just remember that poses are not always an efficient solution to a programming algorithm, and that there are many other viable solutions. The attached proggie uses only a single array, and the positions of the objects in the array to generate a random number of steps.
I left a key item visible so that you could see what's going on, but it can easily be made invisible. There is also no need for a function because the stepcount variable is global.
The two code blocks are disabled, so you can enable the first to view it, then disable it and enable the second to run the test.
Collisions are sometimes good for you