[SV]Randomize Queue SystemVerilog

                         Randomize Queue SystemVerilog

       In most of the queue use cases, queue is used as buffer or temporary storage. so there wont be much need to randomize queue.

 

一、randomize queue size

     In below example, queue size will get randomized based on size constraint, and queue elements will get random values

  1. Declare queue with rand
  2. On randomization queue will get random values
class queue_rand;
  rand bit [7:0] qu[$];
   
  constraint size_c  { 
    qu.size() inside {[4:10]}; 
  }
   
  function void display();
    $display("qu size is = %0d", qu.size());
    $display("qu = %p",qu);
  endfunction
endclass
 
program queue_randomization;
  queue_rand pkt;
 
  initial begin
    pkt = new();
    pkt.randomize();
    pkt.display();  
  end
endprogram

Simulator Output: 

qu size is = 7
qu = ‘{‘h88, ‘h9b, ‘h9a, ‘h10, ‘h5f, ‘hde, ‘h84}

发布了145 篇原创文章 · 获赞 81 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/gsjthxy/article/details/105125520
今日推荐