Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to randomize an array of bit arrays in verilog?

I am new to Verilog.

How can I randomize the following:

 bit [7:0] data [];

*Without use randomize() of systemVerilog.

like image 890
sara8d Avatar asked Jan 24 '26 17:01

sara8d


1 Answers

SystemVerilog will not change the size of a dynamic array unless you put a constraint on it. So you either need to allocate the array before calling randomize(), or use a constraint to randomize the size.

bit [7:0] data [];

data = new[10];
randomize(data);

or

bit [7:0] data [];

randomize(data) with {data.size inside {[5:15]} ;};

or if you do not have access to the randomize() SystemVerilog, you can do

  data = new[10];
  foreach(data[ii]) data[ii] = $urandom;
like image 130
dave_59 Avatar answered Jan 26 '26 10:01

dave_59



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!