Hi, You are not randomizing for multiple times to make sure that, the list will be used once again. Please remember that post randomize will be executed only after the completion of randomization. That’s why you are not getting the expected result. Please find the below code to generate unique numbers.
module tb;
class matrix;
rand bit [4:0] arr [3][3];
constraint c1{foreach(arr[i,j])
foreach(arr[,k])
if(j != k)
arr[i][j] != arr[i][k];}
constraint c2{foreach(arr[i,j])
foreach(arr[k,])
if(i != k)
arr[i][j] != arr[k][j];}
endclass : matrix
matrix m1;
initial
begin
m1 = new();
if (!m1.randomize())
$display("Error");
$display ("%p",m1.arr);
end
endmodule
Hope this helps.
Putta Satish,
Maven Silicon Softech Pvt. Ltd.
I modified your code a bit and seems to be working as you expected
class matrix;
rand bit [4:0] arr [3][3];
constraint a_cst
{
unique {arr};
}
endclass : matrix
module tb;
matrix m1;
initial
begin
m1 = new();
repeat(10)
begin
if (!m1.randomize())
$display("Error");
$display ("%p",m1.arr);
end
end
endmodule