Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 29892d8

Browse files
committed
Use whrandom instead of rand.
Run 500 steps instead of forever.
1 parent 15527e9 commit 29892d8

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

Demo/tkinter/guido/electrons.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,19 @@ def __init__(self, n, bitmap = None):
4141
self.tk.update()
4242

4343
def random_move(self,n):
44+
import whrandom
45+
c = self.canvas
4446
for i in range(1,n+1):
4547
p = self.pieces[i]
46-
c = self.canvas
47-
import rand
48-
x = rand.choice(range(-2,4))
49-
y = rand.choice(range(-3,4))
48+
x = whrandom.choice(range(-2,4))
49+
y = whrandom.choice(range(-3,4))
5050
c.move(p, x, y)
5151
self.tk.update()
5252

5353
# Run -- never returns
5454
def run(self):
5555
try:
56-
while 1:
56+
for i in range(500):
5757
self.random_move(self.n)
5858
except TclError:
5959
try:

0 commit comments

Comments
 (0)