This may work under certain circumstances. But I think the for loops and list(dataset) will be infinite and there is no IndexError, hence, no end to the iteration.
PS. Assuming the implementation is like this
act_index = random.randint(0, len(self.images)-1)
Minus 1 is missing.