title: Generate n random numbers whose sum is m and all numbers should be greater than zero
body: <p>I want to generate 9 non zero random numbers whose sum is 250.
  I have tried following code it gives me 9 random numbers but some numbers are zero.</p>
  
  <pre><code> public void n_random()
  {
    Random r = new Random();
  ArrayList&lt;Integer&gt; load = new ArrayList&lt;Integer&gt;();
      int temp = 0;
      int sum = 0;
      for (int i = 1; i &lt;= 9; i++) {
          if (!(i == 9)) {
              temp = r.nextInt(250 - sum);
              System.out.println("Temp " + (i) + "    " + temp);
              load.add(temp);
              sum += temp;
  
          } else {
              int last = (250 - sum);
              load.add(last);
              sum += last;
          }
      }
  
      System.out.println("Random arraylist " + load);
      System.out.println("Sum is "+ sum);
  
  }
  </code></pre>
  
  <p>Where is my mistake or where i should improve my code or any other solution?</p>