title: Simulating portfolio weights subject to multiple constraints
body: <p>Using R, I would like to simulate a number of feasible portfolios which contain different combinations of assets. I would like to generalize the constraints and be able to add more asset classes in if necessary. </p>
  
  <p>For example, assume there are 4 asset classes, each subject to the following constraints:</p>
  
  <ul>
  <li>0 &lt;= x1 &lt; 0.5</li>
  <li>0 &lt;= x2 &lt; 0.3</li>
  <li>0 &lt;= x3 &lt; 0.5</li>
  <li>0 &lt;= x4 &lt; 1</li>
  <li>x1 + x2 + x3 + x4 = 1</li>
  </ul>
  
  <p>How can I simulate 10 000 random portfolios (or matrices in this case) that satisfy all those conditions without simulating all combinations first and then throwing away the ones that do not satisfy the conditions? I do not want to scale portfolios that do not satisfy the last condition either. Any help would be greatly appreciated! </p>