title: Constrain total number of array elements less than predetermined value
body: <p>I'm trying to create an array with a constraint on the total number of array elements less than given value. For example, I want to generate a random array where the total number of elements less than 4 is no more than 6. The way I implement it is:</p>
  <pre><code>function automatic int get_small_vals(input bit [3 : 0] bit_vector [64]);
      automatic bit [3 : 0] q [$];
      q = bit_vector.find(x) with (x &lt; 4'd4);
      return q.size();
  endfunction
  
  class InputData;
      rand bit [3 : 0] abs_vals [64];
      constraint no_more_than_p_small_values {
          get_small_vals(abs_vals) &lt; 6;
      }
      function void display();
          foreach (abs_vals[i]) $write(&quot;%1h&quot;, abs_vals[i]);
          $write(&quot;\n&quot;);
      endfunction
  endclass
  
  initial begin
      InputData rels;
      rels = new();
      rels.randomize();
      rels.display();
      #100;
      $stop;
  end
  </code></pre>
  <p>I see in the console (Vivado 2018.3 64bit) that there are more than 6 values which are less than 4:</p>
  <pre><code>WARNING: File: C:/my_path/unit_tb.sv Line: 69 : randomize failed to meet constraint.
  902ed8fb3af155c14a5402c092709a999d7f0b2adbd6e7d6d698a7d5c2b5baa7
  </code></pre>
  <p>I can't understand what's the problem.  It works with 'equal', but not with 'less than':</p>
  <pre><code>function automatic int get_small_vals(input bit [3 : 0] bit_vector [64]);
      automatic bit [3 : 0] q [$];
      q = bit_vector.find(x) with (x == 4'd4);
      return q.size();
  endfunction
  </code></pre>