Inactive Tutor answered 03/01/23
Tutor
New to Wyzant
import random
retries = 0
def unique_random_ints(how_many, max_num):
global retries
lst = []
success = True
while len(lst) < how_many:
newInt = random.randint(0,max_num)
if newInt not in lst:
lst.append(newInt)
else:
retries += 1
success = False
while not success:
newInt = random.randint(0,max_num)
if newInt not in lst:
success = True
lst.append(newInt)
break
retries += 1
return lst
def main():
sseed = int(input("Enter seed: "))
how_many = int(input("Enter how many: "))
max_num = int(input("Enter max num: "))
random.seed(sseed)
lst = unique_random_ints(how_many,max_num)
for n in lst:
print(str(n) + " ", end = '')
print("retries=" + str(retries))
if __name__ == "__main__":
main()
Inactive Tutor
Hello. The code is provided. Please let me know if you need me to make any adjustments. I was not 100% sure how your inputs (seed, max_num, how_many) will be provided. I assumed they were live user inputs like the picture shows.03/01/23