Use random module instead of whrandom

Move imports to top
This commit is contained in:
Andrew M. Kuchling 2002-04-10 14:50:16 +00:00
parent 3b2625ff82
commit 9a62448d2f
1 changed files with 4 additions and 4 deletions

View File

@ -17,6 +17,9 @@
# Make board updates faster # Make board updates faster
# #
import random, string, traceback
import curses
class LifeBoard: class LifeBoard:
"""Encapsulates a Life board """Encapsulates a Life board
@ -118,11 +121,10 @@ class LifeBoard:
def makeRandom(self): def makeRandom(self):
"Fill the board with a random pattern" "Fill the board with a random pattern"
import whrandom
self.state={} self.state={}
for i in range(0, self.X): for i in range(0, self.X):
for j in range(0, self.Y): for j in range(0, self.Y):
if whrandom.random()*10>5.0: self.set(j,i) if random.random() > 0.5: self.set(j,i)
def erase_menu(stdscr, menu_y): def erase_menu(stdscr, menu_y):
@ -139,7 +141,6 @@ def display_menu(stdscr, menu_y):
'E)rase the board, R)andom fill, S)tep once or C)ontinuously, Q)uit') 'E)rase the board, R)andom fill, S)tep once or C)ontinuously, Q)uit')
def main(stdscr): def main(stdscr):
import string, curses
# Clear the screen and display the menu of keys # Clear the screen and display the menu of keys
stdscr.clear() stdscr.clear()
@ -196,7 +197,6 @@ def main(stdscr):
else: pass # Ignore incorrect keys else: pass # Ignore incorrect keys
if __name__=='__main__': if __name__=='__main__':
import curses, traceback
try: try:
# Initialize curses # Initialize curses
stdscr=curses.initscr() stdscr=curses.initscr()