Computer Science > QUESTIONS & ANSWERS > University of Illinois, Urbana Champaign CS CS 101 Generating a Random Walk A random walk in two  (All)

University of Illinois, Urbana Champaign CS CS 101 Generating a Random Walk A random walk in two dimensions along a square grid has equal probability of veering off in any direction. Over time, this... Share Question

Document Content and Description Below

Question Generating a Random Walk A random walk in two dimensions along a square grid has equal probability of veering off in any direction. Over time, this means that the expected total distance ... travel increases, but the mean expected position remains the origin (0,0) Compose a function random_walk_distance which accepts a number of steps n and an optional argument seed with default of 101. This function should return the distance traveled from the origin after a random walk of n steps of size 1, chosen from the four cardinal directions (in order: forward, backward, left, right). Your submission should include a function random_walk_distance( n,seed ). Note that this is just a random walk: there is no figure-of-merit f to track. Starter code def random_walk_distance( n,seed ): # Set the seed. xy = np.random.uniform( size=(2,) ) f = np.array( ( 0,-1 ) ) # "forward" looking at array in quadrant 4 b = np.array( ( 0,+1 ) ) # "back" looking at array in quadrant 4 l = np.array( ( -1,0 ) ) # "left" looking at array in quadrant 4 r = np.array( ( +1,0 ) ) # "right" looking at array in quadrant 4 for i in range( n ): # Take a random step, 25% chance in each direction. chance = np.random.uniform() if chance < 0.25: # Move forward. elif chance < _____: # Move backwards. elif chance < _____: # Move left. a: # Move right. # Split out x and y for convenience and return distance. return np.sqrt( x*x + y*y ) [Show More]

Last updated: 2 years ago

Preview 1 out of 3 pages

Buy Now

Instant download

We Accept:

We Accept
document-preview

Buy this document to get the full access instantly

Instant Download Access after purchase

Buy Now

Instant download

We Accept:

We Accept

Reviews( 0 )

$7.00

Buy Now

We Accept:

We Accept

Instant download

Can't find what you want? Try our AI powered Search

98
0

Document information


Connected school, study & course


About the document


Uploaded On

Apr 22, 2021

Number of pages

3

Written in

Seller


seller-icon
Muchiri

Member since 4 years

209 Documents Sold

Reviews Received
19
5
1
1
6
Additional information

This document has been written for:

Uploaded

Apr 22, 2021

Downloads

 0

Views

 98

Document Keyword Tags


$7.00
What is Scholarfriends

In Scholarfriends, a student can earn by offering help to other student. Students can help other students with materials by upploading their notes and earn money.

We are here to help

We're available through e-mail, Twitter, Facebook, and live chat.
 FAQ
 Questions? Leave a message!

Follow us on
 Twitter

Copyright © Scholarfriends · High quality services·