mardi 18 octobre 2016

How can I make this loop stop at a certain variable occurs

I need to write a script that generates random numbers between 1-257000 and stops when a certain number occurs telling me how many numbers it generated so far.

i manged to get this far but can't seem to get it to stop or count

x=1
while x < 257000:
    import itertools
    import random

    def random_gen(low, high):
        while True:
            yield random.randrange(1, 257000)

    gen = random_gen(1, 100)
    items = list(itertools.islice(gen, 10))

    print items
    x = x+1

Thank you so much for your help




Aucun commentaire:

Enregistrer un commentaire