Trying to randomize a queue with inside operator. Not getting a desired outcome


class my_class;
  randc int queue [$]; //Unbounded queue
  function void display();
    $display("queue is %p",queue);
  endfunction
  constraint q_size { queue.size()==10; }
  constraint q_val {
  foreach(queue[i]) queue[i] inside [30:39];
    
  }
    endclass

module top;
  my_class obj;
  
  initial begin
    obj=new();
    assert(obj.randomize());
    obj.display();
  end
endmodule

In reply to saikanthan7798:

Please use code tags making your code easier to read. I have added them for you.
There was a syntax error in the second constraint that I fixed. This works for me:


class my_class;
  randc int queue [$]; //Unbounded queue

  function void display();
    $display("queue is %p",queue);
  endfunction

  constraint q_size { queue.size()==10; }

  constraint q_val {
    foreach(queue[i]) queue[i] inside {[30:39]};
  }
endclass

module top;
  my_class obj;

  initial begin
    obj=new();
    if (!obj.randomize()) $display("Randomization failed!");
    else obj.display();
  end
endmodule

In reply to cgales:

What does if (!obj.randomize() do? Does it randomize paralelly?

In reply to saikanthan7798:

You might want to look at my session on SystemVerilog constraints