I have a code where a variable is declared inside task. How do i constraint a below such that it doesnt have back 2 back value of 15? There are other tasks in the same class which will have their own local variable.
class test;
task hello();
int a;
std::randomize(a) with {a inside {0,4'b1111};};
$display ("a value is %d",a);
endtask
endclass
module tb;
test t1;
initial begin
t1 = new();
repeat (10) begin
//if (!t1.randomize()) $display ("Error");
t1.hello();
end
end
endmodule
class test;
int prev_a ;
task hello( inout int prev_a );
int a; // automatic variable , will exist per call .
if( std::randomize(a) with {a inside {0,4'b1111}; a != prev_a ; } )
begin
prev_a = a ;
$display ("a value is %d",a);
end
else
$display (" Randomization Failed ");
endtask
endclass
module tb;
test t1;
initial begin
int previous_a ;
t1 = new();
repeat (10) begin
//if (!t1.randomize()) $display ("Error");
t1.hello( previous_a );
end
end
endmodule
In reply to yourcheers:
but there is a compl err:
keyword const is not expected to be used in this context
my code is :
std::randomize(a) with {const’(a) == 7 → a == 0;};
Thanks ABD :) I slightly modified it. but mostly your code fits my need.
// Code your testbench here
// or browse Examples
class test;
// int prev_a ;
task hello( );
int a,prev_a; // automatic variable , will exist per call .
if( std::randomize(a) with {a inside {0,4'b1111}; if (a==4'b1111)a != prev_a ; } )
begin
prev_a = a ;
$display ("a value is %d",a);
end
else
$display (" Randomization Failed ");
endtask
endclass
module tb;
test t1;
initial begin
t1 = new();
repeat (10) begin
//if (!t1.randomize()) $display ("Error");
t1.hello( );
end
end
endmodule