# How do I disable pre\_randomize function?

**URL:** <https://verificationacademy.com/forums/t/how-do-i-disable-pre-randomize-function/48840>\
**Category:** SystemVerilog\
**Created:** [October 30, 2024, 10:49am UTC](https://verificationacademy.com/forums/t/how-do-i-disable-pre-randomize-function/48840 "2024-10-30T10:49:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gn223](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/g/ed655f/32.png) [@gn223](https://verificationacademy.com/forums/u/gn223)\
**Post date:** [October 30, 2024, 10:49am UTC](https://verificationacademy.com/forums/t/how-do-i-disable-pre-randomize-function/48840/1 "2024-10-30T10:49:31Z")

</div>

How do I disable pre\_randomize function that gets called by default for a particular instance of class when I do class\_h.randomize()? other class handles can call randomize and then call pre\_randomize function by default and execute but not for this specific handle. is extending and overriding pre\_randomize the only possible solution? other solution would be: std::randomize(c1\_h.r1) with {c1\_h.r1 == 3;};

```auto
module m1;

  class c1;
  rand int r1;
  int r2;
  
  constraint c1_c{(r2!=0) -> r1 == r2;}
  
  function void pre_randomize();
    r2 = 'd2;
  endfunction
  
  endclass
  
  initial begin
    c1 c1_h = new();
    c1 c11_h = new();
    c1_h.randomize();//how to disable pre_randomize to this handle only
    c11_h.randomize();
    $display("r1 is %0d", c1_h.r1);
    $display("r1 is %0d", c11_h.r1);
  end
  
endmodule

```

---

<div class="post-metadata">

**Author:** ![MICRO\_91](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/m/5f9b8f/32.png) [@MICRO\_91](https://verificationacademy.com/forums/u/MICRO_91)\
**Post date:** [October 31, 2024, 2:15pm UTC](https://verificationacademy.com/forums/t/how-do-i-disable-pre-randomize-function/48840/2 "2024-10-31T14:15:36Z")

</div>

You could have a separate property for this within class c1

```auto
 class c1;
  bit skip_pre_rand ;
  .....
  function void pre_randomize();
      if( !skip_pre_rand) begin
          r2 = 'd2; 
      end
  endfunction
endclass

 c1 c1_h , c11_h;

   initial begin
     c1_h = new();
   c11_h = new();
  c11_h.skip_pre_rand = 1;
    c1_h.randomize(); // Should check the Success / failure of randomize()
    c11_h.randomize(); // Should check the Success / failure of randomize()
    $display("r1 is %0d", c1_h.r1);
    $display("r1 is %0d", c11_h.r1);
  end
  
endmodule

```

---

<div class="post-metadata">

**Author:** ![gn223](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/g/ed655f/32.png) [@gn223](https://verificationacademy.com/forums/u/gn223)\
**Post date:** [November 2, 2024, 5:59am UTC](https://verificationacademy.com/forums/t/how-do-i-disable-pre-randomize-function/48840/3 "2024-11-02T05:59:50Z")

</div>

Thanks!
