def to_char_random(act_type, from_char, identifier_list, change_type_list=(4, 1), insert_sample_weight=(1, 3, 6)): OTHER_WORD = 0 CONFUSE_WORD = 1 INSERT_WORD = 2 to_char = '' change_type = util.weight_choice(change_type_list) if from_char == '': change_type = OTHER_WORD if change_type == OTHER_WORD: if from_char in identifier_list: to_char = random.sample(identifier_list, 1)[0] elif from_char in keyword_map.values(): to_char = random.sample(list(keyword_map.values()), 1)[0] elif from_char in operator_map.values(): to_char = random.sample(list(operator_map.values()), 1)[0] else: i = util.weight_choice(insert_sample_weight) if i == 0: range_list = identifier_list elif i == 1: range_list = list(keyword_map.values()) else: range_list = list(operator_map.values()) to_char = random.sample(range_list, 1)[0] else: to_char = fake_name(from_char) if act_type == DELETE: to_char = '' return to_char
def action_type_random(type_list=(5, 1, 4)): i = util.weight_choice(type_list) return i
def create_error_action_fn(): i = util.weight_choice(list(zip(*error_creator_list))[2]) return error_creator_list[i][1]