title: Is there a way to limit 7 randomized variables to a sum of 40?
body: <p>I want to make a randomizer for the SPECIAL stats from Fallout New Vegas, i've built most of the code, but there's cases that the sum of the variables exceed/are below the cap of 40.</p>
  <p>Is there a way to limit them, or in cases that the sum is below or over 40, distribute the difference?</p>
  <pre><code>strength = random.randint(1, 10)
  perception = random.randint(1, 10)
  endurance = random.randint(1, 10)
  charisma = random.randint(1, 10)
  intelligence = random.randint(1, 10)
  agility = random.randint(1, 10)
  luck = random.randint(1, 10)
  sum = strength + perception + endurance + charisma + intelligence + agility + luck
  
  diff = 40 - sum
  if diff &lt; 0:
      diff = (diff * - 1)
  
  print(&quot;=======================&quot;)
  print(&quot;Strength:&quot;, strength)
  print(&quot;Perception:&quot;, perception)
  print(&quot;Endurance:&quot;, endurance)
  print(&quot;Charisma:&quot;, charisma)
  print(&quot;Intelligence:&quot;, intelligence)
  print(&quot;Agility:&quot;, agility)
  print(&quot;Luck:&quot;, luck)
  print(&quot;Total:&quot;, sum)
  print(&quot;Difference:&quot;, diff)
  print(&quot;=======================&quot;)
  </code></pre>