I'm trying to get 6 random generated numbers between 1 and 3600. But I want that the the individual numbers to have a minimum difference of at least 150. I already have created a function. I do receive my 6 random numbers but not the difference i expected. Where is my mistake? I can't figure it out.
I'm very new to python. I tried different methods but I'm not able to find the solution for my problem.
def get_random_seconds_with_difference(min_tx, max_tx, number_tx):
s_times = [];
i_number = 0;
new_times_s = random.randint(min_tx,max_tx);
s_times.append(new_times_s);
while i_number < number_tx:
new_times_s = random.randint(min_tx,max_tx);
if new_times_s >= s_times[i_number]:
difference_time_s = new_times_s - s_times[i_number];
else:
difference_time_s = s_times[i_number] - new_times_s;
if difference_time_s >= 150:
s_times.append(new_times_s);
i_number += 1;
return s_times;
Aucun commentaire:
Enregistrer un commentaire