Randomizing MDA with constraints on count of entries

There is no solution that would allow the difference between any of the RGB counts to be 1 or less. The best you could do is all a difference of 2.

let ABS(v1,v2) = v1>v2? v1-v2:v2-v1;
class rgb_matrix;
    typedef enum {RED, GREEN, BLUE} val_e;
    rand val_e mda[3][3];
   rand byte Rc, Gc, Bc;
   
   constraint c_sums {
      Rc == mda.sum(D1) with (D1.sum(D2) with (byte'(D2 == RED)));
      Gc == mda.sum(D1) with (D1.sum(D2) with (byte'(D2 == GREEN)));
      Bc == mda.sum(D1) with (D1.sum(D2) with (byte'(D2 == BLUE)));
   }
   constraint c_diff { ABS(Rc,Gc) <3; ABS(Rc,Bc) <3; ABS(Gc,Bc) <3; }
endclass : rgb_matrix

module top;
   rgb_matrix rgbs = new;

  initial repeat(10) begin
     assert(rgbs.randomize());
     $display("%p",rgbs);
  end
endmodule : top