def _random_replacement(working_on: List[str]) -> List[str]:
     p_per_char = 1.0 / len(working_on)
     return [
         randomness.next_char()
         if randomness.next_float() < p_per_char else char
         for char in working_on
     ]
 def _random_insertion(working_on: List[str]) -> List[str]:
     pos = 0
     if len(working_on) > 0:
         pos = randomness.next_int(0, len(working_on) + 1)
     alpha = 0.5
     exponent = 1
     while (randomness.next_float() <= pow(alpha, exponent)
            and len(working_on) < config.INSTANCE.string_length):
         exponent += 1
         working_on = working_on[:pos] + [randomness.next_char()
                                          ] + working_on[pos:]
     return working_on
Пример #3
0
def test_next_char_printable():
    assert randomness.next_char() in string.printable