mardi 21 avril 2020

Why randint returns the same number in nested for loop

I'm trying to determine 5 lists of 5 random ints (5 move plans for 5 cops) like this:

def algorithm(self, worlds_list_copy):

        for i in range(c_t_m.number_of_cops):
            # r = 0
            # vector = []
            for j in range(c_t_m.k):
                # vector.append(randint(0, 4))
                # random.seed()
                r = random.randint(0, 4)
                self.move_plan[i][j] = r
                # r = 0
            # self.move_plan[i] = vector

But what happens is every cop ends up with the same list:

Planned moves for the cop 0 :
LEFT RIGHT LEFT DOWN UP 
Planned moves for the cop 1 :
LEFT RIGHT LEFT DOWN UP 

And so on for every cop




Aucun commentaire:

Enregistrer un commentaire