Posts

check the value 12321 is pallindrome or not by using constraint

module test(); class packet; rand bit [7:0\] a; constraint a{a inside {[0:4]};} constraint a2 { foreach(a[i])  { a[i]==a[(n-1)-i];}} endclass packet p1=new(); assert(p1.ramdomize()); $display("the value is =%p", p1.a); endmodule

print the prime number 0 to 500 by using constraint

 module test(); class packet; rand bit [15:0] a; constraint a { a inside  {[0:500];} constraint a2 { foreach(a[i]) if(i>1) a[i]==prime(i);} endclass packet p1=new(); assert(p1.randomize()); $display("the value is = %p", p1.a); endmodule

print the values 34,24,[23:40], 50, 30 by using constraint

 module test(); class packet; rand bit [7:0] a; constraint a1 { a inside {[ 34, [23:40], 50, 30]};} endclass packet p1=new(); assert(p1.randomize()); $display("the value is =%p", p1.a); endmodule

print the inside values 1.30 to 2.39 by using constraint

 module test(); class packet; rand bit [7:0] a; int real b;  constraint a {a inside {[130:239];} function void post_randomize(); b=a/10.00; endfunction endclass packet p1=new(); assert(p1.randomize()); $display(the value is =%p", p1.a); endmodule

print the power of 2 by using constraint

 module test(); class packet; rand bit [7:0] a; rand int power; constraint a1{ a inside {[10:20]};} constraint a2 { a==power**2;} endclass packet p1=new(); assert(p1.ramdomize()); $display("the value is =%p", p1.a); endmodule

print the pattern 10101010 by using constraint

 code:- module test(); class packet; rand bit [7:0] a; constraint a1 (a inside {[0:10]};} constraint a2 { foreach(a[i]) if(i%2==0) a[i]==1; else  a[i]==0;} endclass packet p1=new(); assert(p1.randomize()); $display("the value is =%p", p1.a); endmodule

print the odd numbers in even location and even numbers in odd locations by using constraint

 module test(); class packet; rand bit [7:0] a; constraint  a { a inside {[10:20]};} constraint a2 { foreach(a[i]) if(i%2==0) a[i]==1; else a[i]==0;} endclass packet p1=new(); assert(p1.randomize()); $display("the value is=%p", p1.a); endmodule