lundi 12 juillet 2021

get random integers from range of integers

so I need to make a list of unique random integers from a range (start, stop) with a specific number of integers (number_of_ints. so basically a function get_unique_random_integers(1, 100, 10) should return a list with 10 integers, f.ex. [93, 23, 6, 26, 90, 29, 59, 12, 15, 86]. it's also required to use the while loop and randint function. so far I wrote this but the function is returning None.

import random
def get_unique_random_integers(start, stop, number_of_ints):
    random_list = []
    while int(start) < int(stop):
        res = random.randint(start, stop)
        if res not in random_list:
            start += 1
    return random_list.append(res*number_of_ints)
print(get_unique_random_integers(1, 100, 10))

any thoughts or tips much appreciated cheers




Aucun commentaire:

Enregistrer un commentaire