Randomization of dynamic array using "with"

Hi,

When I try randomizing a sequence like this:

if(!seq.randomize() with {
  _num inside {[0:10]};
  _arr     == '{8'h11, 8'h22, 8'h33};
}) begin
  `uvm_error("TST", "Randomization failed")
end

I get this error in Questa 10.5:

(vopt-2936) Illegal non-integral expression in random constraint.

The variables are defined as follows:

rand int         _num;
rand logic [7:0] _arr [];

I have made an example of the problem on EDA Playground:

If you go there and comment:

_arr     == '{8'h11, 8'h22, 8'h33};

in testbench.sv and

arr == _arr;

in a_seq.svh, the code runs properly.

What is the problem with the code and is there correct way to achieve this, or an acceptable workaround?

In reply to evilpascal:
The problem is as the error message tells you - constraint expressions need to be with integral expressions. An unpacked array is not an integral expression. you need to create a separate array, and then use a
foreach
loop and break the aggregate constraint into an set of integral constraints.

bit [7:0] set_arr;

set_arr = '{8'h11, 8'h22, 8'h33};
if(!seq.randomize() with {
  _num inside {[0:10]};
  foreach (set_arr[ii]) _arr[ii] == set_arr[ii];
}) begin
  `uvm_error("TST", "Randomization failed")
end

In reply to dave_59:

Thanks for the soulution dave_59. I just needed to also constrain the “_arr” variable size to the size of the “set_arr”, or there would be a failure when simulation is started:

if(!seq.randomize() with {
  _num inside {[0:10]};
  _arr.size() == set_arr.size();
  foreach (set_arr[ii]) _arr[ii] == set_arr[ii];
}) begin
  `uvm_error("TST", "Randomization failed")
end