I did some tests on your code with the aforementioned range change <0,1), <1,2), <2,3), <3,4), which makes them even.
And you do it like this:
if (nextStep < 1) ++moveWest; else if (nextStep < 2) ++moveEast; else if (nextStep < 3) ++moveSouth; else if (nextStep < 4)++moveNorth;
Pay attention to <= , becoming < .
100,000 tests in 100 steps each gave these results:
Average distance is 8.873435509749317 steps away of from the starting point W=2498906 E=2501447 N=2500022 S=2499625
, where W, E, N, S are the summarized steps for a given direction during all tests. They look great.
Running such a test case a couple of times shows that there is no preferred direction. You can use other methods to get random numbers, but this will be testing the generators, not your business. Your code looks fine from my point of view.
The sentence from the problem proposal also gives you the key: Theoretical answer: in the order sqrt (N).
source share