Unwanted re-programming on same address of memory

You create a list of address and use the inside operator to write a constraint that says when there is a write command, the address cannot be inside the list.

typedef bit [4:0] addr_t;
typedef enum {write, read, erase} cmd_e;
rand cmd_e cmd;
rand addr_t addr;
addr_t list[addr_t];

constraint no_erase { (cmd == write) -> !(addr inside {list});}
  function void post_randomize();
    case(cmd)
    write: list[addr] = addr; // add address to list
    erase: list.delete(addr);
    endcase
endfunction