Hi,
Can anyone please help me write the code for the following question:
There is an array of i elements. Write a constraint to put random even numbers (choose any even number from 1 to 100) in the odd ith element of the array and random odd numbers (choose any odd number from 1 to 100) in the even ith element of the array.
Thanks,
Sruthi.
In reply to sruthikrapa:
module test;
class A;
rand int a[] ;
constraint C1 {a.size() == 50;}
constraint C2 { foreach(a[i])
{
if(i%2 == 0)
a[i]%2 != 0;
else
a[i]%2 == 0;
a[i] inside {[1:100]};
}
}
endclass
A a_h;
initial begin
a_h = new();
begin
assert(a_h.randomize());
foreach(a_h.a[i])
$display(" a [%0d] = %0d",i,a_h.a[i]);
end
end
endmodule
I think this will work
Thanks,
Naveen
In reply to naveen4860:
Hi Naveen,
It worked. Thank you very much.
Regards,
Sruthi.