Hello, I am trying to randomize an array with the dist keyword, so that I could restrict the elements’s size as well as the weight of each range, so that 80% of the time, I’ll get with in range 20~30, 10% between 60~70 and 10% between 90~100.
But the generated array seems to have bigger values than 100.
class Item #(type DATA_WIDTH = bit [7:0], int arraysize = 10);
static int count;
int ID;
rand DATA_WIDTH array [];
function new();
count++;
ID = count;
endfunction
function void show();
$display("Pkt ID %d Data Array :: %p", ID, array);
endfunction
constraint array_c {array.size() == arraysize;
foreach (array[i]) array[i] dist {[20:30]:=80, [60:70]:=10, [90:100]:=10};
}
endclass
The generated Array is::
Pkt ID 1 Data Array :: '{87,240,208,133,25,51,204,112,35,156,246,61,207,194,173,243,95,163,48,46,102,221,33,197,129,
81,243,231,47,21,172,176,102,159,151,149,180,67,69,27,226,220,176,151,31,246,178,2,210,98}