Pattern

In reply to Vikas Misra:

For me, it’s working.
I am getting the required output.


class numbers_sequence;
rand bit [2:0] numbers[9];
constraint const_c {
foreach(numbers[i])
{if(i<=4) numbers[i]==(i+1);
else numbers[i]==9-i;
}
}
endclass

module top;
numbers_sequence o;

initial
begin
o=new();
o.randomize();
$display("the numbers: %p",o.numbers);
end
endmodule

Ouput :

vsim -voptargs=+acc=npr

run -all

the numbers: '{1, 2, 3, 4, 5, 4, 3, 2, 1}

exit