In reply to ce_2015:
For an associative array, we can’t add/remove items in randomize()
I guess you want to do the following:
the first time .randomize() will return default lookup table.
but then if you randomize again, it will randomize existed element in this associative array.
class txn;
typedef enum bit [3:0] {A,B,C,D} sometype_t;
rand int array[sometype_t] = '{default:0};
function void post_randomize(); // first randomize will set to default vaule
if (array.num()==0) begin
array = '{A:1, B:2, C:3, D:4};
end
endfunction
endclass