I ran into this problem while trying to create a procedural texture algorithm. I ended up using a greedy approximation and shuffling it to hide the bias, but I was wondering if there was a way to find a uniform solution.
The Problem
Divide a wall of a height $H$ into a layers whose individual sizes range from $L_{min}$ to $L_{max}$. The algorithm should choose a random solution from the set of all possible layer counts and sizes that satisfy the constraints.
To put it another way, I'm looking for a way to randomly select a set $S$ from the sets that satisfy the constraints for the given $H$, $L_{min}$, and $L_{max}$: $$\sum_iS_i = H$$ $$\forall i | L_{min} \le S_i \le L_{max}$$
It seems similar to a combinatorial optimization problem, but over an infinite set rather than a finite one. Looking at the Wikipedia article, it could be expressed as a knapsack problem whose items are all real numbers in the size interval and whose values are random with the additional constraint that the weight must exactly equal the limit.
Examples
Setting the input parameters $H=10, L_{min}=2, L_{max}=3$ yields an infinite number of possible solutions:
- $\{2, 2, 2, 2, 2\}$
- $\{2, 2, 3, 3\}$
- $\{2.1, 2.5, 2.6, 2.8\}$
- ... and many more
The goal is to choose one of these solutions at random. In this case, the chosen solution would almost certainly have four elements (layers), as there is only one five element option and an uncountable number of four element options.
If we increase $H$ to $10.1$, we suddenly have an uncountable number of five-element solutions:
- $\{2, 2, 2, 2, 2.1\}$
- $\{2.01, 2.03, 2.05, 2.07, 2.09\}$
- etc… In this case, four-element solutions would still be more common, but the random algorithm should occasionally produce a five-element solution.
My Analysis
I wrote a quick program to count up solutions using fixed steps in layer sizes in the hopes that there were exploitable patterns in the distribution. When grouped by layer count, the first layer's size followed a combination counting function with $n$ equal to the number of layers and $k$ linearly related to layer size, but I couldn't find a consistent pattern to how the scale or offset were determined.
Edit: Added examples section. Minor changes to wording.