I have a following structure:
dictionary{ key: dictionar2{ key2: list[ dict3{ 'int_count': value }, dict4{ key4: value }, dict5{ key5: value } ] }
I want to update the value of dict3 with randomly generated values within the range of [0, old_value]. I have two loops. I want to ensure that the new values generated for dict3 are unique for each run of the outer while loop. It's okay if the for loop iterations have similar sequences. Since I have to compare the difference in the results of each iteration of the while loop, this kinda behavior is needed.
counter = 0
max_int_val = 8
# copy "int_Count" entries from original dictionary
dict_old_int_count = {k: v[0]["int_count"] for k, v in data_dict.items()}
while max_int_val >= counter: # run until the max_int_val
for key, inner_dict in data_dict.items():
if inner_dict[0]["int_count"] > 0:
old_int_count = dict_old_int_count[key]
# random value range [0, old_int_count]
inner_dict[0]["int_count"] = random.randint(0, old_int_count)
counter += 1 # need counter for file names
I want to make sure that the sequence of the random values generated within "for" loop isn't same for each iteration of "while" loop. For e.g.
while():
Pass1:
data_dict{ "name01": inner_dict[0]["int_count"] = 2,
"name02": inner_dict[0]["int_count"] = 1}
"name03": inner_dict[0]["int_count"] = 3,
"name04": inner_dict[0]["int_count"] = 1}
"name05": inner_dict[0]["int_count"] = 4,
"name06": inner_dict[0]["int_count"] = 0}
}
|
|
|
|
|
Pass7:
data_dict{ "name01": inner_dict[0]["int_count"] = 2,
"name02": inner_dict[0]["int_count"] = 1}
"name03": inner_dict[0]["int_count"] = 3,
"name04": inner_dict[0]["int_count"] = 0}
"name05": inner_dict[0]["int_count"] = 4,
"name06": inner_dict[0]["int_count"] = 1}
}
In the example above, the values of name01, name02, name03 for pass1 and pass7 are exactly same. The need to not to have this kinda similar sequences for each iteration of while loop.
I hope I was able to clear what's expected.
Aucun commentaire:
Enregistrer un commentaire