lundi 19 décembre 2022

How can you generate a unique list of random integers? [duplicate]

My task is to create two functions: function 1: checks if the randomly generated list is all unique integers function 2: generates a random list of integers.

my function 1 works. my question is for function 2: I know how to randomly generate integers... But I really can't figure out how to randomly generate a list?

import random
#check for unique integers in list
def allunique(x):
    unique_or_not= []
    for item in x:
        if item in unique_or_not:
            return False
        unique_or_not.append(item)
    return True


#need 3 inputs of the # of values to generate, starting # in range of list, ending # in range of list
def list_of_nums():
    num_of_values= int(input("Please enter the number of values you wish to generate:"))
    start= int(input("Please enter the starting # of the values you wish to generate:"))
    end= int(input("Please enter the end # of the values you wish to generate:"))



    for i in range(0,num_of_values):
#have to loop to do it a certain amount of times, append value immediately to list:????



Aucun commentaire:

Enregistrer un commentaire