In Associative array, assign 50 random int values at random locations

In Associative array, assign 50 random int values at random locations
But array size 100.
so how to put the value in different random location.

Code:::

class assoc_array;
  rand int unsigned array [$];
   
  constraint ar_exp {array.size() == 100;}
  
  constraint ar_exp1 {foreach(array[i]) array[i] < 50;} 
   
   function void display();
    $display("array size is = %0d",array.size());
    $display("array = %p",array);
  endfunction
endclass
  
module assoc_array_randomization;
  assoc_array pkt;
 
  initial begin
    pkt = new();
    assert(pkt.randomize());
    pkt.display();  
  end
endmodule

::: OUTPUT :::

array size is = 100

array = '{1, 13, 35, 11, 38, 39, 2, 16, 30, 8, 33, 38, 31, 35, 17, 30, 8, 9, 11, 19, 39, 38, 35, 43, 11, 6, 11, 21, 28, 33, 14, 5, 18, 41, 16, 39, 12, 13, 47, 42, 25, 25, 9, 13, 13, 39, 34, 36, 39, 22, 41, 36, 37, 40, 45, 19, 43, 23, 1, 13, 45, 42, 26, 30, 17, 49, 46, 12, 6, 17, 0, 4, 40, 17, 0, 7, 36, 10, 24, 45, 31, 1, 7, 48, 33, 26, 49, 26, 1, 8, 37, 39, 23, 31, 44, 36, 33, 48, 17, 34}

In reply to Bharat.manvani:

Your problem does not make sense, or is incompletely specified.

You cannot change the size of an associative array, you can only add or delete locations (called a keyed index in SystemVerilog) . Randomization cannot change the key of any location.

This means you either have to populate an associative array with the locations allocated bore calling randomize() which would randomize the array element values, or you can randomize an array of key/value pairs and use post_randomize to construct an associative array from those pairs.

In reply to Bharat.manvani:

I think what you created is a queue not an associative array right?