]> granicus.if.org Git - python/commitdiff
Use whrandom instead of rand.
authorGuido van Rossum <guido@python.org>
Tue, 19 May 1998 21:16:10 +0000 (21:16 +0000)
committerGuido van Rossum <guido@python.org>
Tue, 19 May 1998 21:16:10 +0000 (21:16 +0000)
Run 500 steps instead of forever.

Demo/tkinter/guido/electrons.py

index f16c3fa531d5aa61a3dbfd768f22b767c68f02ff..377c9ed1b4527210f236956810488fcd79141922 100755 (executable)
@@ -41,19 +41,19 @@ class Electrons:
                self.tk.update()
 
        def random_move(self,n):
+               import whrandom
+               c = self.canvas
                for i in range(1,n+1):
                        p = self.pieces[i]
-                       c = self.canvas
-                       import rand
-                       x = rand.choice(range(-2,4))
-                       y = rand.choice(range(-3,4))
+                       x = whrandom.choice(range(-2,4))
+                       y = whrandom.choice(range(-3,4))
                        c.move(p, x, y)
                self.tk.update()
 
        # Run -- never returns
        def run(self):
                try:
-                       while 1:
+                       for i in range(500):
                                self.random_move(self.n)
                except TclError:
                        try: