Dhanu P.

asked • 11/30/22

11.11 Lab: Unique random numbers (random module)

Given integer inputs seed, how_many, and max_num, generate a list of how_many unique random integers from 0 to max_num (inclusive).

  1. Complete function unique_random_ints(how_many, max_num):
  2. Generate a list of how_many random integers from 0 to max_num (inclusive).
  3. When a random number exists in the list, a new random number must be generated; use a global variable, retries, to count the number of times an existing number is generated.
  4. Return the list.
  5. Complete __main__:
  6. Initialize the random module with the seed value.
  7. Call unique_random_ints() to get a list of random integers.
  8. Output the list of random integers and the value of retries, according to the output format shown in the example below.

Refer to the section on the standard library to learn more about the random module and pseudo-random numbers.

Ex: If the input is:

2
5
7

the output is

0 1 5 2 4 retries=1


1 Expert Answer

By:

Sophie V. answered • 03/01/23

Tutor
5 (6)

Software Engineer Specializing in Python, CS Degree

Sophie V.

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.
Report

03/01/23

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.