randomization at the bottom of the snippet. (everything else is my practice in MXS)
delete objects
/**************** make a pattern piece */
ad =
(
a = tube radius1:25 radius2:15 height:10 slice:on sliceto:270 sides:12 pos:[-20,0,0]
b = tube radius1:25 radius2:15 height:10 slice:on slicefrom:90 sides:12 pos:[20,0,0]
c = box width:10 length:40 lengthsegs:12 height:10 pos:[0,20,0]
d = tube radius1:25 radius2:15 height:10 slice:on slicefrom:90 sides:12 pos:[20,-40,0]
e = tube radius1:25 radius2:15 height:10 slice:on slicefrom:270 sliceto:180 sides:12 pos:[-20,00,0]
converttomesh a
a += b
a += c
delete b
delete c
a.wirecolor = orange
centerpivot a
converttomesh a
d += e
delete e
centerpivot d
d.wirecolor = brown
#(a, d)
)
/************ clone pieces and collect */
targets = #()
for y=1 to 9 do for x=1 to 9 do append targets (copy ad[random 1 2] pos:[40*x, 40*y, 5] wirecolor:green)
/******** randomize pieces z-rotations */
(
in coordsys local about pivot (for target in targets do rotate target (angleaxis (random 0 3 * 90) z_axis))
)