Selecting a number from an array, only allowing certain numbers to follow

I wanted to update this question with a possible solution I found myself, but I think this might be a really huge workaround.

Second to that, I realized that I also would have to write code that compares the connections with each other in the Y-direction. Now I’m not asking for anyone to write the code for me, but are there techniques I can read about that I can try out that will help me make a comparison in both the X and Y direction without having to do all of this manually?

Partial solution:

float x = 0;
float y = 0;
float spacing = 30;
float lineSpc = spacing/2;
float radius = spacing*2;
int a = 0;
int b = floor(random(4));

void setup() {
  background(51);
  size(600, 600);
  pixelDensity(displayDensity());
  noFill();
  strokeWeight(spacing/6.67);
  stroke(255);
  strokeCap(PROJECT);
}

int[][] options = { {1, 2, 4, 6}, 
                    {0, 5}, 
                    {3, 7},
                    {1, 2},
                    {6},
                    {0},
                    {1, 2},
                    {3}  };

void draw() {
  float rnd = options[a][b];

  if (rnd == 0) {
    //A0
    float xx = -lineSpc;
    float yy = -lineSpc;
    arc(x + spacing + xx, y + spacing + yy, radius, radius, radians(0), radians(90), OPEN);
    println(a + " & " + b + " = " + options[a][b]);
    a = 0;
    b = floor(random(3));
  } else if (rnd == 1) {
    //A1
    float xx = lineSpc;
    float yy = -lineSpc;
    arc(x + spacing + xx, y + spacing + yy, radius, radius, radians(90), radians(180), OPEN);
    println(a + " & " + b + " = " + options[a][b]);
    a = 1;
    b = floor(random(2));
  } else if (rnd == 2) {
    //A2
    float xx = lineSpc;
    float yy = lineSpc;
    arc(x + spacing + xx, y + spacing + yy, radius, radius, radians(180), radians(270), OPEN);
    println(a + " & " + b + " = " + options[a][b]);
    a = 2;
    b = floor(random(2));
  } else if (rnd == 3) {
    //A3
    float xx = -lineSpc;
    float yy = lineSpc;
    arc(x + spacing + xx, y + spacing + yy, radius, radius, radians(270), radians(360), OPEN);
    println(a + " & " + b + " = " + options[a][b]);
    a = 3;
    b = floor(random(2));
  } else if (rnd == 4) {
    //B0
    line(x+spacing+lineSpc, y+lineSpc, x+spacing+lineSpc, y + spacing+lineSpc);
    println(a + " & " + b + " = " + options[a][b]);
    a = 4;
    b = floor(random(1));
  } else if (rnd == 5) {
    //B1
    line(x+lineSpc, y + spacing+lineSpc, x + spacing+lineSpc, y + spacing+lineSpc);
    println(a + " & " + b + " = " + options[a][b]);
    a = 5;
    b = floor(random(1));
  } else if (rnd == 6) {
    //B2
    line(x+lineSpc, y+lineSpc, x+lineSpc, y + spacing+lineSpc);
    println(a + " & " + b + " = " + options[a][b]);
    a = 6;
    b = floor(random(2));
  } else if (rnd == 7) {
    //B3
    line(x+lineSpc, y+lineSpc, x + spacing+lineSpc, y+lineSpc);
    println(a + " & " + b + " = " + options[a][b]);
    a = 7;
    b = floor(random(1));
  }
  
  x = x + spacing;
  if (x > width-radius) {
    x = 0;
    y = y + spacing;
  }
  if (y > height-radius) {
  //if (y > 10) {
    noLoop();
  }
}