code: def shuffle_genome(genome, cat, fraction = float(100), plot = True, \
          alpha = 0.1, beta = 100000, \
          min_length = 1000, max_length = 200000):
      
      header = '>randomized_%s' % (genome.name)
      sequence = list(''.join([i[1] for i in parse_fasta(genome)]))
      length = len(sequence)
      shuffled = []
      # break genome into pieces
      while sequence is not False:
          s = int(random.gammavariate(alpha, beta))
          if s <= min_length or s >= max_length:
              continue
          if len(sequence) < s:
              seq = sequence[0:]
          else:
              seq = sequence[0:s]
          sequence = sequence[s:]
  #        if bool(random.getrandbits(1)) is True:
  #            seq = rev_c(seq)
  #            print('fragment length: %s reverse complement: True' % ('{:,}'.format(s)), file=sys.stderr)
  #        else:
  #            print('fragment length: %s reverse complement: False' % ('{:,}'.format(s)), file=sys.stderr)
          shuffled.append(''.join(seq))
          if sequence == []:
              break
      # shuffle pieces
      random.shuffle(shuffled)
      # subset fragments
      if fraction == float(100):
          subset = shuffled
      else:
          max_pieces = int(length * fraction/100)
          subset, total = [], 0
          for fragment in shuffled:
              length = len(fragment)
              if total + length <= max_pieces:
                  subset.append(fragment)
                  total += length
              else:
                  diff = max_pieces - total
                  subset.append(fragment[0:diff])
                  break
      # combine sequences, if requested
      if cat is True:
          yield [header, ''.join(subset)]
      else:
          for i, seq in enumerate(subset):
              yield ['%s fragment:%s' % (header, i), seq]
docs: randomly shuffle genome