# Room dimentions ratio, propability function.

This topic is 4760 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I want to create random sized rooms for my game. So, given a certain area of a rectangle room I need to decide what will be its dimentions (X and Y). To simplfy the problem, I only need to randomly roll the proportion between the room's X and Y. While R>1 is a constant of the largest ratio possible. The values of the random variable should be between 1/R to R. Lets call this random variable L. So for some number 1<a<R, P(L<1/a)=P(L>a). The final request from L, is that E(L)=1. Also, L must be generate from a combination of one or more unity (U(,)) random variable. Can you help me find this random variable?

##### Share on other sites
There is something I have thought about.
To have random variables X~U(1, R), Y~=(1/R, 1) and a fair coin.
So in propability 0.5 L = X and in propability 0.5 L = Y.
However, EL is not 1.
Or maybe I had a mistake in my calculations of EL?

##### Share on other sites
Trying to come up with a distribution D(1/R, R) that meets your requirements isn't the right way to go about this, or at least it's extremely difficult. Let's say you consider the ratio of X-to-Y, with a range [1,R] that satisfies the constraint XY = A (some area). When you adjust the X-to-Y ratio range to be [1,1/R], it's really the same as the ratio of Y-to-X, over the range [1,R]. So the issue here with a single distribution is that you're dealing with what I would see as a local "compression" over [1/R,1], since it's equivalent to [1,R] if you just switch X and Y however you have two different size ranges for something that's geometrically equivalant. This problem is formalized by the constraint you mention in your post: P(L<1/a)=P(L>a). I'm sure that such a distribution exists, however coming up with it probably involves some complex math and statistics.

But using the apparent symmetry around 1 of [1,R] for X-to-Y and [1,R] for Y-to-X, we can decompose the problem into two uniform distributions M~U(-1,1) and L~U(1,R). L will be the final ratio, however if M>=0 then the ratio is for X-to-Y and if M<0 then the ratio is for Y-to-X. Using your constraints, you can come up with a system of equations to solve for either X or Y as a function of the ratio and the area A, and then using this ratio you can solve for the other length. This construction satisfies all your requirements.

[Edited by - Zipster on October 7, 2005 8:10:22 AM]

##### Share on other sites
The requirement that E(L)=1 seems very arbitrary to me. You probably need something else and didn't think it through. Did you put that requirement so you don't get too many or too few oblong rectangles? Any natural distribution with E(L)=1 will generate more values under 1 than over 1.

It looks to me that the natural quantity to consider in this problem is not the ratio of the too lengths, but the angle that a diagonal forms with one of the sides. That angle would be between atan(1/R) and atan(R), but it turns out that those two angles can be written as 45º-delta and 45º+delta. I think a uniform distribution U(45º-delta, 45º+delta) for the angle will do just fine, or any other symmetric distribution around 45º.

##### Share on other sites
I think the simplest solution is something like this:

Generate a uniform random number L between -R and R
If L < 0, then X = -L, Y = 1.
If L > 0, then X = 1, Y = L.
If L == 0, then X == Y == 1.

##### Share on other sites
Those equations don't take the area constraint into account. Whatever solution you use to find the ratio, you're still going to have to go back and solve for one side and then the other. The angle-based method looks clever, though. As long as you work off symmetry things should be fine.

##### Share on other sites
I did something like what you have wrote.
With X~(1, R) and then using a coin to decide which axis to use.
You were right, the demand that EL=1 was pointless. Because EL is the factored average (dont know how to say it), not a normal average.
What I needed is actually that the nomral average will be 1.

Thanks for all the help.

1. 1
Rutin
29
2. 2
3. 3
4. 4
5. 5

• 13
• 13
• 11
• 10
• 13
• ### Forum Statistics

• Total Topics
632960
• Total Posts
3009471
• ### Who's Online (See full list)

There are no registered users currently online

×