Constraint

Hi Everyone!

How to construct a constraint for a rand variable say ‘num’ that when randomized, the values should be of the logic 7n and 8n where n= ([1:7] && !5) ie; n= 1 to 7 and n !=5.

In reply to Zara:

//Here it is
class rand_ex;
rand int num,n;
constraint num_c {
num inside {7n,8n};
n inside {[1:7]};
n!=5;
solve n before num;
}
endclass

In reply to verif_gal:

Thank you! :) I have tried the code similar to this but it was throwing some errors with syntax. Now finally its error free!

I have randomized the class 30 times and the generated values falls only on these three numbers 7,8 and 14… What changes has to be made to get the remaining desired values?

Can you share your code ? with the code I pasted, its generating a wide range of values.

In reply to verif_gal:

Thank you @verif_gal!

The datatype for ‘num’ I used was bit [3:0], thats the reason it wasn’t generating the other expected values…

Regards :)