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
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
Step by Step Solution
3.61 Rating (176 Votes )
There are 3 Steps involved in it
public static void ra... View full answer
Get step-by-step solutions from verified subject matter experts
