In reply to Shashank Gurijala:
It’s working after adding the following:
class packet;
rand bit [6:0] num;
randc bit [6:0] a;
rand enum {EVEN,ODD} number;
constraint c1 {a inside {35,36,40,45,[52:128]};}
constraint c2 {num == func(a);}
function bit [6:0] func(bit[6:0]a); //edited part
if(a%2 == 0)
begin
number = EVEN;
$display("\nThe number is %0s and %0d",number.name(),a);
end
else if(a%2 != 0)
begin
number = ODD;
$display("\nThe number is %0s and %0d",number.name(),a);
end
endfunction
endclass: packet
module even_odd_number_functional_constraint;
initial
begin
packet pkt = new;
repeat (5)
begin
pkt.randomize();
end
end
endmodule: even_odd_number_functional_constraint
I want to know why there is a need to again declare the data type and the size of bits of ‘a’ inside function despite it being a global variable to the class packet.