So basically, sampling a random number in a rectangle is the same as chosing a random angle and distance from the center of this rectangle and applying a rotation.

In short it will be something like that:

+On what you want
Local number randX=0 //random X position withing the rectangle
Local number randY=0 //random Y position withing the rectangle
Local number randA=0 //random angle before rotation
Local number randD=0 //random distance
-> System: set randX to random(-rectangle.Width/2,rectangle.Width/2)
-> System: set randY to random(-rectangle.Height/2,rectangle.Height/2)
-> System: set randA to angle(0,0,randX,randY)
-> System: set randD to distance(0,0,randX,randY)
-> System: set randX to rectangle.x + cos(randA + rectangle.angle) * randD
-> System: set randY to rectangle.y + sin(randA + rectangle.angle) * randD

Ah, so its get the rectangle's new angle, generate a random angle, get the difference between those, then generate an offset that is the same for both x, and y.

well, it's really generate a random point and then take it's angle AND distance from the origin.

It's not just a random angle

it's not just a random distance frome the origin

it's not event a random angle and a random distance, 'cause you have to stay within the rectangle boundaries. If you take a random angle and then a random distance from the origin (from 0 to how much?), you can't be sure you are within the rectangle. Angle and distance are linked to discribe a specific point.

So it's really a random point you convert into distance and angle from origin -> rotate -> translate.

Be carefull, the layerangle is a bit tricky. I would advise to not use it, especially if you use scrolling. It behave pretty weirdly.

I think that Ash did say somewhere that it's not the layer that rotate but something like, rotate layout -> paste Layer into main canvas -> rotate back. So event layerangle is reversed...

That looks great! although why do you use numbers 4 and 16 instead of expressions of the size of the box? Basically to adapt this for my own purposes, I need to know how to adjust these constants.