You shouldn’t use assert() around a randomize call. The reason for this is that there are times that assertions may be disabled for performance. When a simulator disables assertions, everything inside the assert() statement is ignored, so randomize won’t be called. It is recommended instead to use simple if/else statements:
// randomizing an array whose members are type randc does NOT result in an
// array of unique values. Each individual member is of type randc, and
// independant of other array members.
class randc_array;
randc bit [3:0] byte_array[];
constraint c_size {
byte_array.size ==4;
}
endclass
class randc_array2;
randc bit [3:0] byte_array[4];
endclass
module top;
randc_array RandcArray;
randc_array2 RandcArray2;
initial begin
//this doesnt work (randomizing when I told it NOT to!)
RandcArray = new();
RandcArray.byte_array.rand_mode(0);
if (!RandcArray.randomize()) $display("Randomization failed!");
else $display("%p", RandcArray);
// this works (disabled the randomization)
RandcArray2 = new();
RandcArray2.byte_array.rand_mode(0);
if (!RandcArray2.randomize()) $display("Randomization failed!");
else $display("%p", RandcArray2);
end
endmodule
In Questa, the first randomize() call fails, as expected. Perhaps this is a simulator error.
Loading sv_std.std
Loading work.top_sv_unit(fast)
Loading work.top(fast)
VSIM 1> run -a