I have the following code in which i am trying to make the 5 index to be a 6. and sum to be 20. But i see neither happening. Can you please tell me what is wrong with the code. Thanks
rand int unsigned fibo[8];
constraint pop_1_c
{
foreach (fibo[i])
{
fibo[i] inside {[1:10]};
}
fibo.sum with ( (item.index==5)?6:item)==20;
}
When you are calling it after randomize in the $display or wherever, you are executing an array reduction operation on the array. It uses a value of 6 for index 5. So 'h4 will be replaced by 6 and that adds up to 20.
The exact same thing happens when you put it in a constraint. You are not asking the solver to constrain index 5 to be 6 at all. Refer to dave’s response above for the expansion of the array reduction operation.