Macro - randomly changing the order of selected objects

Welcome.

Is it possible to create a macro that will each time randomly change the order of selected objects?

For example, I have a group that is 160 mm long and consists of different rectangles and I'm looking for a way to randomly change their order on the x-axis while keeping the width of the whole group.

Thank you.