Final answer:
To create a list of unique random integers using Python's random module, initialize a global variable 'retries' to count duplicates, generate random numbers up to 'max_num', track uniqueness, and return the list when 'how_many' unique integers are obtained.
Step-by-step explanation:
To generate a list of unique random integers from 0 to max_num (inclusive) for a given how_many, you can use Python's random module. This task also implies the need for a retry mechanism that counts the number of times a duplicate random number is generated and suggests using a global retries variable. The function unique_random_ints() should keep generating numbers until the desired quantity of unique numbers is reached.
To initialize the random seed, you use the function random.seed(seed). To generate a random integer, you use random.randint(0, max_num). You need to keep generating these numbers and check whether they are unique by comparing them to the existing list of generated numbers. Increment the retries count each time a duplicate number is generated.
Here's how you could structure the Python code for this task:
import random
global retries
retries = 0
def unique_random_ints(how_many, max_num):
unique_numbers = set()
while len(unique_numbers) < how_many:
number = random.randint(0, max_num)
if number in unique_numbers:
retries += 1
else:
unique_numbers.add(number)
return list(unique_numbers)
# __main__
if __name__ == '__main__':
seed = int(input())
random.seed(seed)
random_numbers = unique_random_ints(5, 5)
print(' '.join(map(str, random_numbers)) + ' retries=' + str(retries))