Given a 32 bit address field as a class member, write a constraint to generate a random value such that it always has 10 bits as 1 and no two bits next to each other should be 1. Please solve this I'm unable to proceed

See this about using functions in constraints: Regarding function in constraints

Use an iterative foreach constraint instead of a for loop.

constraint c1 { $countones(value) == 10;
                foreach(value[i]) i>0 -> !(value[i] && value[i + 1]);
}
1 Like