What have you developed so far? What is working for you? What is not working for you? Have you posted your code on EDA Playground so that others can see what you have written?
Also, requirement number 3 is contradictory. If all other bits can be randomized to 0 or any other pattern, then having a ‘1’ is valid and contradicts that there should not be any 1s between the sequences of nine 1s.
Could you run this code and see this what you are expecting.
module tb();
class simple;
bit [63:0]a;
int pos;
rand bit b;
bit flag;
constraint c_value{
flag == 1 -> b==0;
}
function void post_randomize();
if(pos <64) begin
if(b ==1 && pos<=56) begin
a[pos+:9] = 9'b111111111;
pos = pos+9;
flag =1;
end
if(b ==0) begin
pos = pos+1;
flag = 0;
end
end
endfunction
endclass
initial begin
simple s;
s= new();
repeat(64) begin
s.randomize();
end
$display("The array value = %0b", s.a);
end
endmodule
output::
The array value = 1111111110111111111011111111101111111110111111111001111111110
The code works.
Just a small suggestion for code optimization, the class is randomized 64 times even though it completed randomizing the array much earlier So avoid using fixed number “repeat(64)” and we can randomize the repeat loop==width_of_data and with the repeat loop just check if “s.pos ==data_width” just exit the loop.
eg:
repeat(DATA_WIDTH) begin
s.randomize();
if(s.pos==DATA_WIDTH)
break;
end