jeudi 9 août 2018

Generating a random list and termination of it

I made the following code which generates a random letter from list l every 3 seconds. The first part of my question is how do I terminate this process after 1 minute?

import threading
import random
x = []
def printit():
    threading.Timer(3.0, printit).start()
    l = ['a', 'b', 'c', 'd']
    secure_random = random.SystemRandom()
    print x.append(secure_random.choice(l))

printit()

moreover I want to make another list from those randomly chosen letters and call it x the code above does the job, there is a little problem: when I turn the code it starts printing None, and when I interrupt and print x it gives the list of letters and keeps printing None after that, this is because I don't know how to terminate the process after one minute.




Aucun commentaire:

Enregistrer un commentaire