Rakesh,
The following code seems to work in Questa. Though we usually prefer not to this “single-step array randomization” during our training classes, this works on int/bit etc. fairly well.
Can you elaborate on what didn’t work for you?
Regards
Ajeetha, CVC
class test;
rand bit [7:0] da[];
constraint cst_len { da.size inside { 2, 4, 8 }; }
constraint cst_frame_first_byte { da[0] dist { 8'h00:=50, 8'h11:=50};}
function void post_randomize;
$display ("%p", this);
$display ("da.size: %0d", da.size);
endfunction : post_randomize
endclass : test
program p;
test t0;
initial begin : test
t0 = new;
repeat (10) a1: assert (t0.randomize);
end : test
endprogram : p
I want to randomize transaction field and size of that field is configuration parameter.
How can I write the constraints for this field? I have written code like following. It is not working.
// Transaction field Stop bit
rand bit stop_bit;
// constraint for stop bit value
constraint stop_bit_c {
(stop_bit.size == 1) → stop_bit == 1’b1;
(stop_bit.size == 1) → stop_bit == 2’b11;
}