title: Chr() arg not in range python
body: <p>I have been creating a program, and part of it involves modifying a list of characters at random:</p>
  
  <pre><code>    while rel&gt;0:
          pos = random.randint(0,len(out)-1)
          change = random.randint(-1*rel,rel)
          if (change+ord(out[pos]))&gt;=255:
              change = 255-ord(out[pos])
          elif ((ord(out[pos]))-change)&lt;=0:
              change = -1*(ord(out[pos]))
          out[pos] = chr(ord(out[pos])+change)
          rel -= abs(change)
  </code></pre>
  
  <p>Here, rel is the 'currency' the program is using to modify the list of characters out. It first chooses a random position in the list, and a random amount of change for that position between -rel and +rel, then changes the value of that character using chr(ord(out[pos])+change). This was giving me the error that this new modified value for the character was out of the range(256), so I added the 2 if statements to be executed before changing the character, however it still occasionally returns this error, especially for large values of rel. How can I stop this?</p>