title: Exclude some fields from randomization during a generation run
body: <p>I wan't to exclude some fields from randomization based on a certain condition that is itself determined during the same randomization run. This means I can't use <code>rand_mode(0)</code> as this needs to be called before a call to <code>randomize()</code>.</p>
  
  <p>Here's a simple example of what I mean. Let's say I have a class with 2 integer fields and a boolean that decides whether to randomize the second field or to keep its value constant (i.e. the one before a call to <code>randomize()</code>):</p>
  
  <pre><code>class some_item;
    rand bit do_rand_other_field;
    rand int some_field;
    rand int some_other_field;
  
    // ...
  endclass
  </code></pre>
  
  <p>The only thing I can come up with is to declare an extra local field that will store the value of <code>some_other_field</code> before a randomization run:</p>
  
  <pre><code>class some_item;
    // ...
  
    local int some_other_field_init;
  
    function void pre_randomize();
      some_other_field_init = some_other_field;
    endfunction
  
    // ...
  endclass
  </code></pre>
  
  <p>When <code>do_rand_other_field</code> is not true, I just constrain the field to take its initial value:</p>
  
  <pre><code>class some_item;
    // ...
  
    constraint randomize_some_other_field {
      if (!do_rand_other_field)
        some_other_field == some_other_field_init;
    }
  
    // ...
  endclass
  </code></pre>
  
  <p>This works, but if I have many such conditionally randomized fields it can become inefficient to store and copy them all. I could declare these "initial" fields as <code>static</code> and this would reduce the memory consumption, but the run-time penalty of copying would still be there.</p>
  
  <p>The randomization engine has to store these values somewhere, since in case of a constraint contradiction it will return the un-randomized object. I'd like to find a way to tap into these value. Is there any feature of the language that I overlooked that could help me do this?</p>