const len = 10; // ur array len
const a = ... // fill array, all zeroes
const directions = [
{name: 'up', addx: 0, addy:-1},
{name: 'down', addx: 0, addy:+0},
{name: 'left', addx: -1, addy:0},
{name: 'right', addx: +1, addy:0}
];
function getNextStep(prevStep) {
// random choose between directions with a rule: it may no go inverse
// eg if prevStep is 'up', then return may not be 'down'. Same for 'left', no return 'right'. No arg = does not matter
}
var pathX = 0,
pathY = Math.trunc(Math.random() * len / 2);