Choose random numbers according to certain math rule

How do I choose certain numbers that fulfill a certain relationship between them? The simplest case, for example: choose a and b positive real numbers such that a+b = 20. Something more complicated, for example: how to choose a, b, c and d positive real numbers such that a.b = c /d^2.

Are there any procedures that do this relatively quickly?

a=rand(); b = 20-rand()

1 Like

Do you know anything about the distributions? In the second case, for instance, you can choose three variables independently, and the fourth will be determined (4 variables - 1 equation = 3 degrees of freedom). But if you want the three chosen to be, for example, normally distributed, the fourth will not be. So it matters which one you choose to be dependent.

1 Like

The first case is not simpler, btw. It actually introduces the complication that a,b \leq 20, or the other one is not a positive real. This risk does not occur in the second case.

For complex relations between parameters, isn’t this a case for using MCMC methods?