dimanche 30 juillet 2017

Python random.randint() keeps returning 0 after certain time

I was trying to get 3 random numbers within range in python without replacement. I did this

rand_lst = []

while(True):
    rand = random.randint(0, length-1 )
    if(len(rand_lst) == 3):
         break
    if(rand not in rand_lst):
         rand_lst.append(rand)

This code is inside a for loop. This returns only 0 and thus an infinite loop. I also tried numpy.random.randint but some how random is keeping track of previously generated numbers and I endup with value error.




Aucun commentaire:

Enregistrer un commentaire