0

Ive written a program to do with drawing a line from a centre point and it is meant to snake randomly from the centre.

However, it seems to be incredibly biased as to where it decides to go.

the 4 directions are as simple as up down left and right, but it seems to only really head upwards. Yet i can see that some of the numbers do infact tell it to snake downwards, however it seems to make no real difference.

Any suggestions? (I do know there is some redundant code in there, but ill preen that later on.)

Running python 2.6

```
#
#
#
from graphics import *
def main():
numWalks, numSteps, = getInputs()
north,south,east,west = takeWalks(numWalks, numSteps)
def getInputs():
numWalks = input("How many random walks to take? ")
numSteps = input("How many steps for each walk? ")
return numWalks, numSteps
def takeWalks(numWalks, numSteps):
totalSteps = 0
north=0
south=0
east=0
west=0
from math import sqrt
from random import randint
from graphics import *
centre= Point(numWalks*numSteps,numWalks*numSteps)
centrex,centrey=(numWalks*numSteps),(numWalks*numSteps)
x,y=centrex,centrey
win=GraphWin("",(numWalks*2)*numSteps,(numWalks*2)*numSteps)
circle = Circle(centre, numWalks*numSteps)
circle.setWidth(2)
circle.draw(win)
for walk in range(numWalks):
direction = (randint(1,5)+randint(1,5)+randint(1,5)+randint(1,5))/4
for step in range(numSteps):
if direction == 1:
startx,starty=x,y
x,y+x,y+1
line= Line(Point(startx,starty), Point(x,y))
line.draw(win)
elif direction == 2:
startx,starty=x,y
x,y=x,y-1
line= Line(Point(startx,starty), Point(x,y))
line.draw(win)
elif direction == 3:
startx,starty=x,y
x,y=x+1,y
line= Line(Point(startx,starty), Point(x,y))
line.draw(win)
else:
startx,starty=x,y
x,y=x-1,y
line= Line(Point(startx,starty), Point(x,y))
line.draw(win)
print direction
#y1=(north-south)
#x1=(east - west)
#distance = sqrt(x1**2 + y1**2)
return north,south,east,west
def printExpectedDistance(distance):
print "The expected number of steps away from the "
print "start point is", int(distance)
main()
```