Write a method called randomWalk that performs steps of a random one-dimensional walk. The random walk should

Question:

Write a method called randomWalk that performs steps of a random one-dimensional walk. The random walk should begin at position 0. On each step, you should either increase or decrease the position by 1 (each with equal probability). Your code should continue making steps until a position of 3 or -3 is reached, and then report the maximum position that was reached during the walk. The output should look like the following:

Position = 1

Position = 0

Position = –1

Position = –2

Position = –1

Position = –2

Position = –3

Max position = 1

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question
Question Posted: