title: Randomization of a class object inside a class in SystemVerilog
body: <pre><code>class c2;
    rand bit[1:0] a;
    rand bit[1:0] b;
  
    function void my_print();
      $display("a = %b", a);
      $display("b = %b", b);
    endfunction   
  endclass
  
  class c1;
    rand bit[1:0] i;
    rand bit[1:0] j;
    rand c2 o2;
  
    function new();
      o2 = new();
    endfunction
  
    function void my_print();
      $display("i = %b", i);
      $display("j = %b", j);
    endfunction
  endclass
  
  program p1;   
    c1 o1 = new;
    c2 o2_local = new;
  
    initial begin
    if (o1.randomize() with {o2 == o2_local;}) begin
      o1.my_print();
      o2.my_print();
    end
  endprogram
  </code></pre>
  
  <p>In this program, randomization is getting failed for o1.randomize(). If I take individual variables for o2 and use inline constraint with that (like o2.a == o2_local.a), then it works.</p>
  
  <p>Is there any alternative way to do this type of randomization, as my original class contains almost 38 variable, and individual assignments would be troublesome.</p>