<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 1D random walk
50% chance of taking a step to either the left or the right
Step1:  2D random walk
As above, but now in 2D.  Pick random direction, take step of unit length in that direction.
Step2:  asymmetric random walk
in this case, it's somewhat more probable to take a step to the right than to the left.  (Or, if somebody has messed with the parameters, the other way around.)  Note
<ASSISTANT_TASK:>
Python Code:
n_trials = 1000  # number of trials (i.e., number of walks)
n_steps = 1000   # number of steps taken during each trial
distances = []  # use this to keep track of distance for each trial
this_trial = 0
# loop over trials
while this_trial < n_trials:
    # reset step and distance to zero
    this_distance = 0
    step=0
    while(step < n_steps):
        # random number is either 0 or 1 (heads/tails)
        if random.randint(0,1) > 0:
            this_distance += 1
        else:
            this_distance -= 1
        step+=1
    
    # keep track of distances
    distances.append(abs(this_distance))
    this_trial += 1
plt.hist(distances)
distances = np.array(distances) # convert to numpy array to make life easier
# in 1D, asymptotic solution for mean walk length is (n_steps*2/pi)**(1/2)
print(math.sqrt(n_steps*2.0/math.pi),distances.mean(),distances.min(),distances.max())
Explanation: 1D random walk
50% chance of taking a step to either the left or the right
End of explanation
n_trials_2D = 100  # number of trials (i.e., number of walks)
n_steps_2D = 100    # number of steps per trial
distances_2D = []   # to keep track of distances of each walk
this_trial = 0
# lists for x, y position of *each step* for the last trial.
# (This is just for visualization purposes - we want to make a plot.)
xpos=[]
ypos=[]
    
while this_trial < n_trials_2D:
    x,y = 0.0,0.0
    # keep track of walker position for last trial
    if this_trial == n_trials_2D - 1:
        xpos.append(x)
        ypos.append(y)
    
    step=0
    # go until we reach the number of steps we want to take
    while(step < n_steps_2D):
        # pick a random angle between zero and 2*pi
        theta = random.random()*2.0*math.pi
        # step x and y in that direction
        x += math.cos(theta) 
        y += math.sin(theta)
        # if last trial, keep track of walker positions
        if this_trial == n_trials_2D - 1:
            xpos.append(x)
            ypos.append(y)
        
        step+=1
    this_distance = (x**2 + y**2)**0.5
    #print(this_trial, abs(this_distance))
    distances_2D.append(abs(this_distance))
    this_trial += 1
    
plt.hist(distances_2D)
distances_2D = np.array(distances_2D)
# expect roughly sqrt(n_steps_2D) to be the right answer!
print(math.sqrt(n_steps_2D),distances_2D.mean(),distances_2D.min(),distances_2D.max())
plt.plot(0.0,0.0,'ro',xpos,ypos)
#plt.xlim(-16,16)
#plt.ylim(-16,16)
Explanation: 2D random walk
As above, but now in 2D.  Pick random direction, take step of unit length in that direction.
End of explanation
n_trials = 100000
n_steps = 100
prob_right = 0.6
distances = []
this_trial = 0
    
while this_trial < n_trials:
    this_distance = 0
    step=0
    while(step < n_steps):
        if random.random() < prob_right:
            this_distance += 1
        else:
            this_distance -= 1
        step+=1
    
    #print(this_trial, abs(this_distance))
    distances.append(this_distance)
    this_trial += 1
    
    
plt.hist(distances)
distances = np.array(distances)
#print(math.sqrt(n_steps*2.0/math.pi),distances.mean(),distances.min(),distances.max())
Explanation: asymmetric random walk
in this case, it's somewhat more probable to take a step to the right than to the left.  (Or, if somebody has messed with the parameters, the other way around.)  Note: this reduces to the previous 2D case when prob_right = 0.5.
End of explanation
<END_TASK>