This time i am required to write a “random walk” function across a 10 x 10 array. The array will contain characters (all ‘.’ initially). Until this point, to the best of my knowledge, i just create 2D array and assign all [10][10] with '.' initial.
Expand|Select|Wrap|Line Numbers
- for(i=0;i<10;i++)
- {
- for(j=0;j<10;j++)
- {
- a[i][j] = '.';
- }
- }
The function must randomly “walk” from element to element, always going up, down, left, or right by one element. The elements visited by the program will be labeled with the letters A through Z, in the order visited.
So the output should look like this
Expand|Select|Wrap|Line Numbers
- A . . . . . . . . .
- B C D . . . . . . .
- . F E . . . . . . .
- H G . . . . . . . .
- I . . . . . . . . .
- J . . . . . . . Z .
- K . . R S T U V Y .
- L M P Q . . . W X .
- . N O . . . . . . .
- . . . . . . . . . .
The only thing i can tell is the use of srand or rand function is a must to generate random numbers, However to use those randomly generated numbers, i have no idea. I hope someone can help me, thank you for any suggestion to get this program done.