This random layer order script is a handy utility within Randomill that sets up your artboards for further pattern generation. Randomize, reverse, and sort layer order of all objects in a selection with an easy-to-use GUI.
Randomize Mode
Randomill can randomize layer order of all objects in a selection, and even optionally retain parent layer order hierarchy.

Randomize layer order of Adobe Illustrator objects with a single click
Randomizing layer order is a great way to add variety to backgrounds or textural designs quickly and easily. If there are many overlapping objects all stacked on top of each other, this random layer order function can really help bring in some visual interest to the design. It doesn’t get simpler than this one. There are no extra options or checkboxes–just turn on the Layer Order function, select the Randomize mode, and click the run button at the top of the Randomill panel.
Respect parent layers
Choose whether or not layers stay within their own parent layers when they’re randomized, or if layers can move around between parent layers freely.
When checked: layers will only be arranged relative to other selected layers in the same parent layer.
When unchecked: layers will be arranged relative to every selected layer. All layers will also move directly under the first object in the new layer order. If selected objects are scattered throughout multiple parent layers, this will cause them all to end up on the same parent layer.
Use cases
Randomizing layer order with this illustrator script can be a great way of adding some variety and uniform (but non-repetetive) overlapping effects in your designs. This works especially well when working with many overlapping layers that have varying blend modes and opacities. Speaking of those properties, take a look at Randomill’s random opacity and random blend mode functions. Combing Randomill’s various functions together really bring out the full strength of this plugin.

Arrange & Sort
Re-arrange and sort layers in Adobe Illustrator by their position on the artboard. Specify the major and minor axis sorting priority, and get those layers organized.

Sort layer order by position
This function is a great way to organize your layer stack, and prep it for subsequent uses of other Randomill functions. Most of Randomill’s functions depend on layer order. For example, all of the ‘shift’, ‘target’, and ‘oscillate’ modes are reliant on the layer order of objects. Therefore, users must have the ability to quickly arrange layer order in preparation for use of these functions. That’s where this function shines. When using this function, all selected objects will be sorted by their (X, Y) positions in the document, with the topmost, leftmost, rightmost, or bottommost object ending up on top of the layer stack depending on which sub-mode you choose.
Flip minor axis sorting
This function flips the tiebreak sorting priority measurement to act in reverse. What does this mean? Let’s say you’re sorting a group of objects so that the top-most objects in the document are on top of the layer stack. However, all of the objects happen to occupy the exact same place in the Y direction, but occupy different places in the X direction. Randomill would have to resort to sorting objects in the X direction since the Y coordinate for each object is the same. By default, Randomill would prioritize objects on the left. Checking this options would make it so Randomill prioritizes objects on the right.
If the major axis between two compared objects is the same, Randomill sorts along the minor axis. This checkbox allows users to change the priority of the minor axis.
Use cases
Let’s say you have a bunch of objects scattered in a random layer order, and you want a seamless color blend to go between these objects from top-to-bottom.
Because the color blend function in Randomill works by iterating over objects based on their layer order, you need to first sort these objects based on their Y position in the document.
You could simply select the ‘Top-most objects on top’ radio in the Randomill interface, execute the layer arrange function, and you’d then be ready to perform the color blend.

Reverse Mode
Reverse layer order in Adobe Illustrator with the click of a button.

This function is really simple. It will reverse the layer order of all selected objects in the document. The way it does this depends on whether or not the ‘respect parent layers’ checkbox is checked or not. Intermediate unselected layers are unchanged in terms of their position in the layer stack.
Use cases
Many of Randomill’s functions are dependent on the layer order of the objects it operates on. For example, shifting scale down 1% from object to object will look very different among objects that are arranged in reverse order in the layer stack. Sometimes, you may want to execute an operation in Randomill in ‘reverse order’. To accomplish this, you would first have to reverse the layer order using this function, then execute whatever operation you were trying to do. You can always just reverse the layer order back when you’re done.

