title: How can I find a set of random numbers that sum to a specific number?
body: <p>This is my code below. The code itself echoes if the sum of three of random numbers equals 100. For now to get a result of 100 as <code>$valuestotal</code> I have to reload the page a lot. But I want to get the result of 100 as <code>$valuestotal</code> every time I reload the page. How can I do this?</p>
  
  <p>I thought it would be possible with a loop in loop. But it gives the same result x times. I want PHP to keep trying different random values, and when it reaches to the value of 100 as <code>$valuestotal</code>, it should echo the <code>$valuestotal</code>...</p>
  
  <p>What I really want is, for example, I want three random numbers to get total of 100, example is 35 and 25 and 50. Or 25 and 15 and 60... the list goes on...</p>
  
  <p>How is this possible?</p>
  
  <pre><code>$values = rand(1, 100);
  $values2 = rand(1, 100);
  $values3 = rand(1, 100);
  
  $valuestotal = $values + $values2 + $values3;
  
          //
  
  while ($valuestotal === 100)
  {
      echo $values;
      echo '&lt;br&gt;';
      echo $values2;
      echo '&lt;br&gt;';
      echo $values3;
      echo "&lt;br&gt;";
      echo $valuestotal;
  
  }
  </code></pre>