title: Cannot figure out improper string splicing
body: <p>I am making a function which takes a tuple containing strings, selects one string, then selects a start and end index within that string. Within this index, the string is chopped up into pieces and permuted randomly and then the tuple is returned with the modified string. However, there appears to be some sort of error when defining the start and end index in the function and then splicing the string based on it. In some runs it works as expected, and in others it does not and hence throws an error which I avoid in the while loop. Can anyone tell me what could be going on here:</p>
  <pre><code>def chromothripsist(seqs, keep_frequency = 0.9):
  seqs = list(seqs)
  c = list(range(len(seqs)))
  chrom = random.sample(c, 1)
  orig_seq = seqs[chrom[0]]
  n = len(orig_seq)
  NotLongEnough = True
  while(NotLongEnough): 
      splits = random.randint(5,10)
      ##IF SPLITS &gt; len(seq) then this bugs 
      print(orig_seq)
      lowbd = int(0.1*n)
      upbd = int(0.9*n)
      distance = int(np.random.uniform(lowbd, upbd))
      stidx = random.randint(0,n-1)
      edidx = max(stidx + distance, n-1)
      dist = edidx - stidx
      print(splits, stidx, edidx)
      if(dist &gt; splits): 
          NotLongEnough = False
          break
  first_part = orig_seq[:stidx]
  last_part = orig_seq[edidx:]
  seq = orig_seq[stidx:edidx]
  # THE ABOVE LINES ARE NOT WORKING AS EXPECTED
  print(seq)
  print(stidx, edidx)
  print(len(seq), splits)
  breakpoints = np.random.choice(len(seq), splits-1, replace = False)
  breakpoints.sort()
  subseq = []
  curridx = 0
  for i in breakpoints: 
      subseq.append(seq[curridx:i])
      curridx = i
  subseq.append(seq[breakpoints[-1]:])
  rearrange = np.random.permutation(splits)
  #n_to_select= int(splits *keep_frequency)
  n_to_select = len(rearrange)
  rearrange = random.sample(list(rearrange), n_to_select)
  build_seq = ''
  for i in rearrange: 
      build_seq += subseq[i]
  seqs[chrom[0]] = first_part + build_seq + last_part
  breakpoints = list(breakpoints)
  return tuple(seqs), [stidx, edidx, breakpoints, rearrange, chrom[0]]
  </code></pre>