mardi 28 novembre 2017

How to use either random.sample or random.choice to choose multiple numbers from a randomly generated list

I have to randomly generate 100 7-digit numbers, then I have to generate 10 random numbers from those 100 numbers. I have started with:

import random

def main():

my_list= list(random.sample(range(1000000, 10000000), 100))

print(my_list)

print(random.choice(my_list))

main()

Unfortunately I am not sure how to get the function random.choice to select multiple (10) numbers. Should I use random.sample again? And if so, how do I get the function to understand the list of the 100 7-digit numbers as integers?




Aucun commentaire:

Enregistrer un commentaire