(s, p=0.01, n=None)
return s.tostring()
Flip a given percentage or number of bits from a string
Flip a given percentage or number of bits from a string
Flip a given percentage or number of bits from a string
def corrupt_bits(s, p=0.01, n=None):
    """Flip a given percentage or number of bits from a string"""
    s = array.array("B",str(s))
    l = len(s)*8
    if n is None:
        n = max(1,int(l*p))
    for i in random.sample(xrange(l), n):
        s[i/8] ^= 1 << (i%8)
    return s.tostring()
def corrupt_bits ( s , p = 0.01 , n = None ) : s = array . array ( "B" , str ( s ) ) l = len ( s ) * 8 if n is None : n = max ( 1 , int ( l * p ) ) for i in random . sample ( xrange ( l ) , n ) : s [ i / 8 ] ^= 1 << ( i % 8 ) return s . tostring ( )