import random import string import json def generate_random_string(n): letters = string.digits #string.ascii_letters + string.digits return ''.join(random.choice(letters) for _ in range(n)) def generate_non_consecutive_integer(n): digits = list(range(10)) random.shuffle(digits) if digits[0] == 0: digits[0], digits[1] = digits[1], digits[0] unique_integer = [str(digits[0])] for _ in range(n - 1): next_digit = str(random.choice([d for d in digits if d != int(unique_integer[-1])])) unique_integer.append(next_digit) return int(''.join(unique_integer)) def create_ten_passwords(length_list): pswds = [] for num in length_list: password = int(generate_non_consecutive_integer(n=num)) while len(str(password)) != num: password = int(generate_non_consecutive_integer(n=num)) pswds.append(password) return [pswds] def create_rounds(seed=8,length_list=[12,12,10,10,8,8,6,6,4,4],num_rounds=10): random.seed(seed) all_tasks = [] for _ in range(10): all_tasks.append(create_ten_passwords(length_list=length_list)) return all_tasks def dump_tasks(folder,type,tasks): with open(f'{folder}/static/{type}/counting_tasks.json', 'w') as outfile: json.dump(tasks,outfile) #decreasing_tasks = create_rounds(seed=7,length_list=[7,7,6,5,4,4,4,4,4,4],num_rounds=8) #dump_tasks('AbilityCode','Code_DecreasingDifficulty',decreasing_tasks) # #decreasing_tasks = create_rounds(seed=89,length_list=[7,7,6,5,4,4,4,4,4,4],num_rounds=5) #dump_tasks('AttentionAllocation','Code_DecreasingDifficulty',decreasing_tasks) # #decreasing_tasks = create_rounds(seed=41,length_list=[7,7,6,5,4,4,4,4,4,4],num_rounds=5) #dump_tasks('Treatment','Code_DecreasingDifficulty',decreasing_tasks)