mardi 29 mars 2016

Random number generator, how to get random numbers that are not the same

I am making a random number generator but I do not want the numbers over again. so for example

[1,2,3,4] is perfect - [1,1,2,4] is not what I want because a number recurring.

I have looked on here and no one has the answer to the problem I am searching for, in my logic this should work but I do not know what I am doing wrong.

I am new to python and I saw a couple questions like mine but none with the same problem

import random, timeit
random_num = random.randint(1,10)
cont_randomized_num = random.randint(1,10)
tries = 0
start = timeit.default_timer()
num_guess = 0
stored_numbers = []

while cont_randomized_num != random_num:
    if cont_randomized_num == stored_numbers:
        cont_randomized_num = random.randint(1,10)
    elif cont_randomized_num != stored_numbers:
        print(num_guess)
        stored_numbers.append(cont_randomized_num)
        print(stored_numbers)
        cont_randomized_num = random.randint(1,10)
        tries +=1

print()
print()
stop = timeit.default_timer()
print(random_num)
print('Number of tries:',tries)
print('Time elapsed:',stop)
input('press ENTER to end')




Aucun commentaire:

Enregistrer un commentaire