Functional constraints

class sample;

rand int i;

rand bit [2:0] array [10];

//constraint array_size {array.size() == 10;}

function bit [2:0] a [10] (int i);

for (i=0;i<=4;i++)

begin

a[i] = i;

$display("a[%0d] = %0d",i,a[i]);

end

for (i=9;i>=6;i--)

begin

a[i] = i;

$display("a[%0d] = %0d",i,a[i]);

end

endfunction

constraint elements {array == a(i);}

endclass


module arrayfunc;

initial

begin

sample s = new;

s.randomize();

end

endmodule

There’s a syntax error and I’m trying to print first 5 elements incrementing and nxt five in decreasing order using functional constraints.

In reply to Shashank Gurijala:

https://verificationacademy.com/forums/systemverilog/constraint-array-10-elements-which-first-5-elements-are-increment-nature-and-next-5-elements-are-decrementing-nature

In reply to Rahulkumar:

I want to use functional constraint and not for each. Is it not possible?