I'm trying to generate a random path from the center of a circle and count how many steps it takes to exit the circle, my programming language is python 2.7. I've imported random and numpy.
I've written some pseudo code to help me keep in mind what I want to accomplish:
Start at center of circle
Keep track of step count
Step distance=1 step
Radius of Circle=500 steps
While location<500 steps from center:
take=1 step in random angle direction
continue while loop
How many steps?
I'm having trouble with every part of this code. I don't know where to begin, I imagine I'd have to append to an array so I can know when I've exited the circle but I have no idea how to keep track of my coordinates.
Update
This is the code I have written so far, it will be updated as I make changes:
import numpy
import random
#Define constants
r=500
step=1
step_count=0
#Defining origin in circle
x=0
y=0
location=(x,y)
#While inside the circle
while (x,y)<r:
x_step=step*numpy.cos(random.randrange(0,2,step=1/180))
y_step=step*numpy.sin(random.randrange(0,2,step=1/180))
location+=(x_step,y_step)
step_count+=1
#Print answer
print step_count
Things to correct:
-
random angle module: since numpy.cos/sin works in radian the random number input will be 0-2 with 1/180 as the step. I'm not sure that random.randrange is set up properly.
-
???
Aucun commentaire:
Enregistrer un commentaire