title: how do you distribute a number throughout a certain amount of fields?
body: <p>Okay so lets say I have number , 100, and I want to split it up into 12 groups randomly and have the total from all the groups equate to 100. How would I do this, I have written a piece of code but it has a flaw.  </p>
  
  <pre><code>from random import randint
  total = 100
  while total &lt; 101:
      for i in range(0,9):
          num = randint(1,total)
          print(i,"|","*"*num)
          total -= num
  if total &lt;= 0:
      for j in range (i,10):
          print(j,"|","*"*total)
  </code></pre>
  
  <p>when you run it , once the total is equal to zero or less, it crashes, so it wont post the full results and I do not know how to deal fix this. I'm new to Python so my knowledge is limited. </p>