Randomly partition an rectangle into N smaller rectangles I'm looking for an algorithm that can partition a rectangle into N smaller rectangles, at random. N will be small (on the order of 5-10 in most cases). It need not be uniformly at random, but at the very least, I'd like to avoid algorithms which completely exclude interesting classes of partitions.

One algorithm I've come across a few times (including a question on Math.SE about the number of ways to do n partitions), is to randomly divide the rectangle in two by drawing an horizontal or vertical line across it, then do the same thing recursively to the resulting smaller rectangles until you get what you want.

The trick here is that although you can get a number of different partitions using this scheme:



There are some ways of dividing a rectangle into smaller rectangles that this method will never produce:



You can easily see that the divide-and-conquer partitioning will never generate the above, because there's no line that could possibly be the first cut, since no single straight line divides the entire square into two smaller rectangles.

So basically I'm looking for an algorithm to randomly divide a rectangle up into N smaller rectangles, where the results meet the following criteria:


Partitioned into exactly N smaller rectangles
Everything must actually be a rectangle (no L shapes, etc)
No empty space left over


The algorithm as a whole should meet the following criteria:


There is no valid partitioning that the algorithm is incapable of producing
Can be biased towards certain types of  configurations, though the less bias the better.
Preferably works with integer indices.
Does not operate by generating all possible partitions and then picking one at random.


I don't care about asymptotic complexity much, because I'll be working with small numbers.
Here's a simple idea that I believe can generate all partitions.  There are two types of subdivisions:


Given a rectangle, randomly generate a horizontal or vertical line to partition it into two subrectangles.  (The usual "split in two" rule.)
Given a rectangle, randomly generate a rectangle that fits inside it.  Consider the 4 corners of this inner contained rectangle: for each of them, flip a coin and draw a line from this corner outwards towards the outer containing rectangle, with the direction of the line (horizontal or vertical) being determined by what the coin says.  Regardless of the directions of the 4 lines, the result will always be 5 rectangles.  (Some partitions that can be generated by rule 1 can also be generated this way -- in fact, only 2 of the 16 possible configurations of lines will produce partitions that could not be produced by rule 1.)


At any point in time you will have a set of rectangles (initially, just the original one).  Randomly choose one to subdivide (or you could, e.g., choose the biggest, etc.), flip a coin to decide which of the two rules to apply to it, and then apply that rule; keep doing this until you have $n$ rectangles.

Disclaimer: I have no idea how to even think about the set of all partitions, let alone whether the above procedure generates them all with equal probability...  Probably not.