Illegal non-integral expression in random constraint

I am getting this below Error. can you tell me what is the problem?

Error: testbench.sv(33): (vopt-2936) Illegal non-integral expression in random constraint



class questions;
  
  rand int r[$];
  rand int xyz[10];
  
  constraint ab {foreach (xyz[i])
    xyz[i] > 0 && xyz[i] < 20; 
                }
  
  
  constraint c {
   
    r == xyz.find(x) with (int'(x<5));
  } 
  
  
  endclass  

module tb;
  questions q1;
  
  
  initial begin
    q1 = new();
    repeat (10) begin
    if (!q1.randomize)$display ("Error");
     
      
      $display ("r %p",q1.r);
      $display ("ac %p",q1.xyz);
    
    
    end
  end
  
endmodule


In reply to rag123:

Your problem is that a SystemVerilog queue (r constraint c) is not an integral variable so you cannot randomize it “directly”, in order to randomize the queue contents you need to use iterative constraints similar as what you did with the array xyz.

From the LRM:
18.5.8 Iterative constraints
Iterative constraints allow arrayed variables to be constrained using loop variables and indexing expressions, or by using array reduction methods.

I have to ask in constraint c, there is nothing random about it why not move it to post_randomize if you need to populate such queue with the elements < 5 from xyz?

HTH,

-R

In reply to rag123:


class questions;

     int r[$];
     rand int xyz[10];
 
     constraint ab {foreach (xyz[i])
              xyz[i] > 0 && xyz[i] < 20; 
     }

     function void post_randomize();
            r = xyz.find(x) with (int'(x<5));              
     endfunction 

  endclass