samedi 21 février 2015

Using Random Once in a While loop

I'm having a bit of a problem using classes while using a random in a while loop. The goal is the first time to generate a random string and to use that throughout the lesson. Here are the four lines with the problem.



def run_review(self, key_history):
level = reviewer.ReviewLesson(self.history_list)
if self.counter:
self.word = level.review()
level.review_lesson()
self.counter = False
if self.counter == False:
level.review_lesson()


from another module



def review(self):
self.word = ' '
shuffled_list = sorted(self.history_list, key=lambda k: random.random())
for item in shuffled_list:
self.word = item+self.word
self.word = self.word*7
return self.word


def review_lesson(self):
word = ''
self.word = word+self.word
return self.word


The issue is after the first block the review_lesson is an empty space since level.review() is not called, however if level.review is called it then becomes another random sequence.





Aucun commentaire:

Enregistrer un commentaire