@conf.commands.register
def corrupt_bytes(s, p=0.01, n=None):
 s = array.array('B', str(s))
 l = len(s)
 if (n is None):
  n = max(1, int((l * p)))
 for i in random.sample(xrange(l), n):
  s[i] = ((s[i] + random.randint(1, 255)) % 256)
 return s.tostring()

@ conf . commands . register def corrupt_bytes ( s , p = 0.01 , n = None ) : s = array . array ( 'B' , str ( s ) ) l = len ( s ) if ( n is None ) : n = max ( 1 , int ( ( l * p ) ) ) for i in random . sample ( xrange ( l ) , n ) : s [ i ] = ( ( s [ i ] + random . randint ( 1 , 255 ) ) % 256 ) return s . tostring ( )
corrupt a given percentage or number of bytes from a string .