Generate random path on a 5x5

Well.
I have a 5x5 matrix, like this one


0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0

Or maybe like this one (doesn’t matter)


1  2  3  4 5
6  7  8  9 10
11 12 13 14 15
16 17 18 19 20
21 22 23 24 25

I want to generate a random path of a length. ( 3>length>22 lets say)
You can only go left right up and down. You can’t cross the path, or go back.

Examples


// random path of length 5
0 0 0 1 0
0 0 0 2 0
0 0 4 3 0
0 0 5 0 0
0 0 0 0 0


// random path of length 9
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
8 7 4 3 2
9 6 5 0 1


// random path of length 6
1 2 3 0 0
0 5 4 0 0
0 6 0 3 0
0 0 0 0 0
0 0 0 0 0

Something like

public List CreateRandomPath(int length)
{
// magic
return the list.
}

The list could be something like 1 2 3 4 (list of numbers)
This would represent the ‘cell’ of the matrix like here


1  2  3  4 5
6  7  8  9 10
11 12 13 14 15
16 17 18 19 20
21 22 23 24 25

ex: 1 would be the first one, 25 the last one, like in that matrix above
Or a Vector2 list, where every point in the path would have the x and y position.
ex: 1,1 would be the first cell, 4,4 the last one…

I hope someone understand :smiley: