I have to randomize an queue without using constraints

Hi There,

Can any one give inputs to this problem. I have to randomize a queue without using constraints.
The queue is bounded queue for example the bounded queue has 20 elements and the queue each elements must be inside 0 to 10.

In reply to marathuteja:

What have you tried??

I just tried this code


class con;
  rand int a [$:4];
  int da [];
  
  function void post_randomize();
    foreach(a[i])
      a[i] = $urandom_range(20,30)
  endfunction
  
endclass

module tb;
  con c;
  initial
    begin
      c = new();
      assert(c.randomize);
      $display("size of ele is %d", c.a.size);
      $display("Queue = %p", c.a);
    end
endmodule

In reply to marathuteja:

A few comments on your code :

  1. Since you have declared property ‘a’ as rand and there are no existing constraints , you could have randomized elements with values b/w 0-10
  2. The $urandom_range(20,30) call in post_randomize doesn’t match your intention .
  3. You haven’t constrained the size to 20 elements .

Just wrote this code, it might fulfill your requirement:


class rand_class;
  int q[$:9];
endclass

module test;
  rand_class rc;
  int p;
  
  initial begin
    rc = new();    
    while(rc.q.size() < 10) begin
      std::randomize(p) with {p inside {[0:10]};};
      rc.q.push_back(p);      
    end
    $display("Size of Queue: %0d", rc.q.size());
    $display("Queue: %0p", rc.q);
  end
endmodule

Output:
Size of Queue: 10
Queue: '{6, 0, 5, 6, 4, 6, 7, 5, 9, 0}