Well your not really looking for a expression here, since maya expressions don't work in way that facilitates this*. Unless of course you make 200 expressions. In which case you could have made 200 key frames equally easily.
Now mayas designed to split the problem into 2 parts, part one is assembly wich in this case is easiest done by a small for loop that generates the key frames for your objects. Or just one anim curve. Depends a bit hw you want your aniamtion controls structured. Now its very important to stress that a expression is not mel. And vice versa.
Analogy, in kitchen you have ingredients and machines, and recipes. The ingredients are 3d equalities of your assets, machines are nodes, and the recipe is mel, A expression is a custom node, but it doe snone theless hve to work with the electric regulations so not to blow a fuse.
Well now you can solve thsi entire problem on recipe level, if not then you will need to solve it ab BOTH recepie and expression level. Off course had you done this cubes first you'd got this copy functionality for free. And could have used a expression woich would have copied 200 times.
One way to solve this is to:
CODE
{//protect namespace
$selection=ls -sl
; //operate on selection
//curve to steer the anim
$curve=createNode -n "myRotation" animCurveTL
;
setKeyframe -t 0 -v 90 $curve;
setKeyframe -t 200 -v 0 $curve;
//prepare the connectors
$out=($curve+".output");
$chans={".rx",".ry",".rz"};
for ($item in $selection){
//randomize connection
$range=createNode -n "range" setRange
;
//offset so it isnt so uniform in timing
//if you want unifrom change to 90 and 0
setAttr ($range+".oldMaxX") (90-rand(0,10));
setAttr ($range+".oldMinX") (rand(0,10));
setAttr ($range+".maxX") (sign(rand(-1,1))*90);
connectAttr -f $out ($range+".valueX");
connectAttr -f ($range+".outValueX") ($item+$chans[(int)floor(rand(0,3))]);
}
}
its a bit involved since you chose to work this direction, tighten the anim curve to suit your need. NOTE this si not a expression
*Well its not so much that you couldn't do this as much as that its not designed to be used this way. But you defninetly don't want to.
See maya works on a graph, and you should no circumnavigate it, this creates just painful misery on your part. Because you'd be doing ALL the work manually. and trust me thats not what you want to do. Best advice you'll ever hear is not to try to fight the built in design constraints.