# \#systemverilog-Arrays

**URL:** https://verificationacademy.com/forums/tag/systemverilog-arrays/5944.md

[Latest](https://verificationacademy.com/forums/latest.md) · [Categories](https://verificationacademy.com/forums/categories.md) · [Tags](https://verificationacademy.com/forums/tags.md)

---

## [Pattern Detector 10110 in SV (no FSM)](https://verificationacademy.com/forums/t/pattern-detector-10110-in-sv-no-fsm/49653)

<div class="topic-metadata">

**Author:** [@CharchicaA](https://verificationacademy.com/forums/u/CharchicaA)\
**Replies:** 1\
**Last updated:** [February 19, 2025, 9:48pm UTC](https://verificationacademy.com/forums/t/pattern-detector-10110-in-sv-no-fsm/49653 "2025-02-19T21:48:49Z")

</div>

Q. Write Code for Pattern Detector 10110. Input to DUT is 1 bit and output is 1 bit. How can I implement without queue? If I change queue to array in below code I get flag=1 twice. Why? EDA Link: EDA Playground D…

---

## [Using sum() to Calculate the Sum of a 2D Array](https://verificationacademy.com/forums/t/using-sum-to-calculate-the-sum-of-a-2d-array/36629)

<div class="topic-metadata">

**Author:** [@amy992](https://verificationacademy.com/forums/u/amy992)\
**Replies:** 11\
**Last updated:** [May 28, 2025, 6:50pm UTC](https://verificationacademy.com/forums/t/using-sum-to-calculate-the-sum-of-a-2d-array/36629 "2025-05-28T18:50:04Z")

</div>

I’d like to know how to calculate the sum of a 2d array using sum() method, or any other more efficient methods. According to the RFM 2017 7.12.3 Array reduction methods, the second example: logic \[7:0\] m \[2\]\[2\] = '{ …

---

## [Initializing a multi-dimentional array to all zeros](https://verificationacademy.com/forums/t/initializing-a-multi-dimentional-array-to-all-zeros/38529)

<div class="topic-metadata">

**Author:** [@Mitu\_Raj](https://verificationacademy.com/forums/u/Mitu_Raj)\
**Replies:** 3\
**Last updated:** [May 15, 2025, 2:17pm UTC](https://verificationacademy.com/forums/t/initializing-a-multi-dimentional-array-to-all-zeros/38529 "2025-05-15T14:17:51Z")

</div>

logic signed \[WIDTH : 0\] rg \[I\] \[J\] ; WIDTH, I, J are parameters. How can I initialise the above array to all zeroes. I know I can do it using nested for loops. But I would like to know the shortest version in Sys…

---

## [Need help with understanding which data structure is good to implement this case](https://verificationacademy.com/forums/t/need-help-with-understanding-which-data-structure-is-good-to-implement-this-case/45975)

<div class="topic-metadata">

**Author:** [@Blitzz0418](https://verificationacademy.com/forums/u/Blitzz0418)\
**Replies:** 4\
**Last updated:** [January 29, 2024, 12:27am UTC](https://verificationacademy.com/forums/t/need-help-with-understanding-which-data-structure-is-good-to-implement-this-case/45975 "2024-01-29T00:27:11Z")

</div>

i Have a requirement to implement a cache in DV environment. i have three caches having different data width and hence LRU width and valid bits width. one way i thought was to have a associative array of struct which …

---

## [Randomize a 2-dimensional array to generate below pattern:](https://verificationacademy.com/forums/t/randomize-a-2-dimensional-array-to-generate-below-pattern/40293)

<div class="topic-metadata">

**Author:** [@Bharat.manvani](https://verificationacademy.com/forums/u/Bharat.manvani)\
**Replies:** 4\
**Last updated:** [January 16, 2024, 6:33pm UTC](https://verificationacademy.com/forums/t/randomize-a-2-dimensional-array-to-generate-below-pattern/40293 "2024-01-16T18:33:27Z")

</div>

Hi I have question about this /\*randomize a 2-dimensional array to generate below pattern: 1 2 3 4 5 2 3 4 5 6 3 4 5 6 7 …

---

## [Sum of array (array constraints)](https://verificationacademy.com/forums/t/sum-of-array-array-constraints/45481)

<div class="topic-metadata">

**Author:** [@VerifEngg](https://verificationacademy.com/forums/u/VerifEngg)\
**Replies:** 2\
**Last updated:** [January 11, 2024, 5:34am UTC](https://verificationacademy.com/forums/t/sum-of-array-array-constraints/45481 "2024-01-11T05:34:05Z")

</div>

I have the code for the following constraint: Sum of all array elements must be 17 Array must have at least one element which is multiple of 4. Size of an array can be anything class Example; rand bit \[15:0\] my\_arr\[…

---

## [Count unique values in an array or a queue](https://verificationacademy.com/forums/t/count-unique-values-in-an-array-or-a-queue/42633)

<div class="topic-metadata">

**Author:** [@tharindu](https://verificationacademy.com/forums/u/tharindu)\
**Replies:** 4\
**Last updated:** [November 3, 2023, 5:52am UTC](https://verificationacademy.com/forums/t/count-unique-values-in-an-array-or-a-queue/42633 "2023-11-03T05:52:27Z")

</div>

Hi All, I want to get the number of unique values in an array / a queue. This method does not work int values\[$\] = '{1,2,3,4,1,2,3,4}; int unique\_value\_count; unique\_value\_count = values.unique().size(); It gives …

---

## [How to set a register to a value thru a hierarchy receiving as string?](https://verificationacademy.com/forums/t/how-to-set-a-register-to-a-value-thru-a-hierarchy-receiving-as-string/42505)

<div class="topic-metadata">

**Author:** [@MahD](https://verificationacademy.com/forums/u/MahD)\
**Replies:** 3\
**Last updated:** [October 4, 2023, 5:25pm UTC](https://verificationacademy.com/forums/t/how-to-set-a-register-to-a-value-thru-a-hierarchy-receiving-as-string/42505 "2023-10-04T17:25:06Z")

</div>

I am going to write to the specific registers filed via the task like follow task automatic set\_register(string block\_name, string register\_file, string register\_name, string field\_name, bit \[3:0\] RegisterValue); …

---

## [Passing array size as argument for another array inside the task/function](https://verificationacademy.com/forums/t/passing-array-size-as-argument-for-another-array-inside-the-task-function/41855)

<div class="topic-metadata">

**Author:** [@gabi0307](https://verificationacademy.com/forums/u/gabi0307)\
**Replies:** 3\
**Last updated:** [June 20, 2023, 6:11pm UTC](https://verificationacademy.com/forums/t/passing-array-size-as-argument-for-another-array-inside-the-task-function/41855 "2023-06-20T18:11:16Z")

</div>

I have an issue where I am trying to pass an array size argument as one of my arguments to the task but it fails. the code is as follows (not the full version only the important bits): parameter SIZE\_1 = 27; task task…

---

## [What causes the failure of the randomization process?](https://verificationacademy.com/forums/t/what-causes-the-failure-of-the-randomization-process/41844)

<div class="topic-metadata">

**Author:** [@UVM\_LOVE](https://verificationacademy.com/forums/u/UVM_LOVE)\
**Replies:** 3\
**Last updated:** [June 19, 2023, 2:33pm UTC](https://verificationacademy.com/forums/t/what-causes-the-failure-of-the-randomization-process/41844 "2023-06-19T14:33:00Z")

</div>

class test\_c; int d\_array\[\]; function my\_rand(); std::randomize(d\_array) with { unique{d\_array}; d\_array.size() inside {\[0:100\]}; d\_array.sum() inside {\[0:100\]}; foreach(d\_array\[i\]) { …

---

## [Comparing Variable slices of Fixed Arrays](https://verificationacademy.com/forums/t/comparing-variable-slices-of-fixed-arrays/35707)

<div class="topic-metadata">

**Author:** [@agstod](https://verificationacademy.com/forums/u/agstod)\
**Replies:** 9\
**Last updated:** [May 22, 2023, 4:54am UTC](https://verificationacademy.com/forums/t/comparing-variable-slices-of-fixed-arrays/35707 "2023-05-22T04:54:13Z")

</div>

I want to compare variable-width slices of fixed arrays. Since the part selects (-:,+:) require a constant width, I can’t use those. My first attempt was to try something like: bit \[31:0\] array1\[100\]; bit \[31:0\] array…

---

## [Constraint for two dimensional array](https://verificationacademy.com/forums/t/constraint-for-two-dimensional-array/40493)

<div class="topic-metadata">

**Author:** [@subbireddy](https://verificationacademy.com/forums/u/subbireddy)\
**Replies:** 16\
**Last updated:** [May 7, 2023, 10:37am UTC](https://verificationacademy.com/forums/t/constraint-for-two-dimensional-array/40493 "2023-05-07T10:37:09Z")

</div>

Two dimensional array need to allocate size and values like below byte array\[i\]\[j\]; i and j should be same value i.e square matrix. i and j values should be any number diagonal matrix left side values should be incre…

---

## [Randc in an variable within an array of objects](https://verificationacademy.com/forums/t/randc-in-an-variable-within-an-array-of-objects/37719)

<div class="topic-metadata">

**Author:** [@AidyLandoRabinovits](https://verificationacademy.com/forums/u/AidyLandoRabinovits)\
**Replies:** 11\
**Last updated:** [May 2, 2023, 6:39am UTC](https://verificationacademy.com/forums/t/randc-in-an-variable-within-an-array-of-objects/37719 "2023-05-02T06:39:11Z")

</div>

I tried to generate an array with different values each items (random value, not the index) my array declared as a randc, but it doesn’t work for me: class fs\_array; randc int unsigned array1\[6\]; constraint c{ …

---

## [Generate NXN Matrix with following rules](https://verificationacademy.com/forums/t/generate-nxn-matrix-with-following-rules/41578)

<div class="topic-metadata">

**Author:** [@Bharat.manvani](https://verificationacademy.com/forums/u/Bharat.manvani)\
**Replies:** 2\
**Last updated:** [April 26, 2023, 4:10pm UTC](https://verificationacademy.com/forums/t/generate-nxn-matrix-with-following-rules/41578 "2023-04-26T16:10:32Z")

</div>

Generate NXN Matrix must following rules sum of 1st raw is 0. sum of 1st column is 0. sum of diagonal is 0. //\* code constraint cons1 {foreach(dyn\[i,j\]) { (dyn\[0\]\[j\]) -\> …

---

## [How to create random dynamic 2D arrays in SystemVerilog?](https://verificationacademy.com/forums/t/how-to-create-random-dynamic-2d-arrays-in-systemverilog/41055)

<div class="topic-metadata">

**Author:** [@UVM\_LOVE](https://verificationacademy.com/forums/u/UVM_LOVE)\
**Replies:** 12\
**Last updated:** [December 5, 2022, 6:38am UTC](https://verificationacademy.com/forums/t/how-to-create-random-dynamic-2d-arrays-in-systemverilog/41055 "2022-12-05T06:38:42Z")

</div>

To trying to generate 2d array, I implement as the below. But I faced randomize fail. assert(pkt.randomize()); | ncsim: \*W,SVRNDF (./test1\_packet.sv,49|20): The randomize method call failed. First data.size is constr…

---

## [How do I define an associative array of queues?](https://verificationacademy.com/forums/t/how-do-i-define-an-associative-array-of-queues/33452)

<div class="topic-metadata">

**Author:** [@VerifEngg](https://verificationacademy.com/forums/u/VerifEngg)\
**Replies:** 15\
**Last updated:** [August 19, 2022, 7:21pm UTC](https://verificationacademy.com/forums/t/how-do-i-define-an-associative-array-of-queues/33452 "2022-08-19T19:21:12Z")

</div>

I want to define an associative array with a pkt\_id (of type int) as the index and each index has a queue. I tried this : bit\[31:0\]trans\_q\[$\]recd\_trans\[\*\]; Does not seem correct. Any inputs?

---

## [Arranging zeroes in an array at odd indices](https://verificationacademy.com/forums/t/arranging-zeroes-in-an-array-at-odd-indices/40333)

<div class="topic-metadata">

**Author:** [@ShashankGurijala](https://verificationacademy.com/forums/u/ShashankGurijala)\
**Replies:** 3\
**Last updated:** [May 2, 2022, 4:44pm UTC](https://verificationacademy.com/forums/t/arranging-zeroes-in-an-array-at-odd-indices/40333 "2022-05-02T16:44:13Z")

</div>

Hello! I’m trying to arrange the zeroes in an array at odd index positions and below is the array and the logic applied. It’s working fine if there are no zeroes preceding at even positions. But it is failing when there …

---

## [Printing non-unique elements in an array](https://verificationacademy.com/forums/t/printing-non-unique-elements-in-an-array/40282)

<div class="topic-metadata">

**Author:** [@ShashankGurijala](https://verificationacademy.com/forums/u/ShashankGurijala)\
**Replies:** 1\
**Last updated:** [April 16, 2022, 5:18pm UTC](https://verificationacademy.com/forums/t/printing-non-unique-elements-in-an-array/40282 "2022-04-16T17:18:37Z")

</div>

I’m trying to print non-unique elements in an array. Consider the program below: module nonunique; int non\_unique\_array \[1:10\]; int i,j,count; initial begin non\_unique\_array = '{5,2,5,2…

---

## [Question on Array.Sum() Method , generate a n\*n matrix such that there is only one 1's in a coloumn](https://verificationacademy.com/forums/t/question-on-array-sum-method-generate-a-n-n-matrix-such-that-there-is-only-one-1s-in-a-coloumn/40145)

<div class="topic-metadata">

**Author:** [@PrabhavaBhat](https://verificationacademy.com/forums/u/PrabhavaBhat)\
**Replies:** 8\
**Last updated:** [March 14, 2022, 8:43pm UTC](https://verificationacademy.com/forums/t/question-on-array-sum-method-generate-a-n-n-matrix-such-that-there-is-only-one-1s-in-a-coloumn/40145 "2022-03-14T20:43:11Z")

</div>

\]I was looking to generate a Matrix Where at any given point there is only one 1's in a coloumn 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 etc.... the goal is just to have one 1 in any given col Based on previous…

---

## [How to use variable for forcing the path](https://verificationacademy.com/forums/t/how-to-use-variable-for-forcing-the-path/40137)

<div class="topic-metadata">

**Author:** [@m\_r\_m](https://verificationacademy.com/forums/u/m_r_m)\
**Replies:** 4\
**Last updated:** [March 11, 2022, 7:25pm UTC](https://verificationacademy.com/forums/t/how-to-use-variable-for-forcing-the-path/40137 "2022-03-11T19:25:25Z")

</div>

task force\_bit(input bit \[3:0\]ramr , input bit \[31:0\] c\_dword); //{ // ramr 0 to 7, c\_dword 0 to 4; //genvar ramr\_loc; //ramr\_loc = ramr; \`ifdef ASIC //generate force \<initial\_path\>.m\_65536x156\_i…

---

## [Array constraint. Each row total should be 100, with each element less than 80. I want to understand how to do this using only sum method of array](https://verificationacademy.com/forums/t/array-constraint-each-row-total-should-be-100-with-each-element-less-than-80-i-want-to-understand-how-to-do-this-using-only-sum-method-of-array/39998)

<div class="topic-metadata">

**Author:** [@vickydhudashia](https://verificationacademy.com/forums/u/vickydhudashia)\
**Replies:** 9\
**Last updated:** [February 25, 2022, 3:21pm UTC](https://verificationacademy.com/forums/t/array-constraint-each-row-total-should-be-100-with-each-element-less-than-80-i-want-to-understand-how-to-do-this-using-only-sum-method-of-array/39998 "2022-02-25T15:21:10Z")

</div>

class fs\_array; rand bit \[7:0\] array1\[3\]\[4\]; int i,j; rand int n; // \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* incorrect output \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* constraint array\_c { foreach (array1\[i\]) { …

---

## [Passing Unpacked Array of Packed Array as task arguments](https://verificationacademy.com/forums/t/passing-unpacked-array-of-packed-array-as-task-arguments/40077)

<div class="topic-metadata">

**Author:** [@Akhil\_Mehta](https://verificationacademy.com/forums/u/Akhil_Mehta)\
**Replies:** 1\
**Last updated:** [February 23, 2022, 5:46pm UTC](https://verificationacademy.com/forums/t/passing-unpacked-array-of-packed-array-as-task-arguments/40077 "2022-02-23T17:46:31Z")

</div>

task xyz(output op, output bit \[width-1:0\] write\_data ); I have my task xyz definiton in an interface. I want to call this task from my testbench.sv So, how should I call it? I am trying to call it in this manner but g…

---

## [What {(a+1)}\[7:0\] implies inside conditional statement?](https://verificationacademy.com/forums/t/what-a-1-7-0-implies-inside-conditional-statement/40022)

<div class="topic-metadata">

**Author:** [@Asraful\_21](https://verificationacademy.com/forums/u/Asraful_21)\
**Replies:** 1\
**Last updated:** [February 2, 2022, 4:35am UTC](https://verificationacademy.com/forums/t/what-a-1-7-0-implies-inside-conditional-statement/40022 "2022-02-02T04:35:30Z")

</div>

module test; bit \[7:0\] a = 8'hFF; bit en = 1; initial begin a = en? {(a+1)}\[7:0\]:0; end endmodule What is meant by {(a+1)} \[7:0\] ? What is the difference between the following statements: a = en? {(a+1)}\[7…

---

## [Constraint for repeating numbers in an array in a unique pattern](https://verificationacademy.com/forums/t/constraint-for-repeating-numbers-in-an-array-in-a-unique-pattern/39994)

<div class="topic-metadata">

**Author:** [@atalur](https://verificationacademy.com/forums/u/atalur)\
**Replies:** 6\
**Last updated:** [January 28, 2022, 8:42pm UTC](https://verificationacademy.com/forums/t/constraint-for-repeating-numbers-in-an-array-in-a-unique-pattern/39994 "2022-01-28T20:42:20Z")

</div>

I am trying to solve a constraint where an array A (say int) has a certain configurable length and its contents are repeated ‘k’ times each except for 1 element that is unique to the array. Example: A (say length 10 and…

---

## [Foreach usage in randomization constraints](https://verificationacademy.com/forums/t/foreach-usage-in-randomization-constraints/34510)

<div class="topic-metadata">

**Author:** [@peterjin](https://verificationacademy.com/forums/u/peterjin)\
**Replies:** 12\
**Last updated:** [November 7, 2021, 10:03pm UTC](https://verificationacademy.com/forums/t/foreach-usage-in-randomization-constraints/34510 "2021-11-07T22:03:12Z")

</div>

Hi, I tried to generate the bath-tub curve distribution using the constraint posted on this verification academy page but got run-time error from the constraint used in it. Here is the constraint used in the page int …

---

## [Reverse an array without using the reverse() function](https://verificationacademy.com/forums/t/reverse-an-array-without-using-the-reverse-function/39756)

<div class="topic-metadata">

**Author:** [@sk7799](https://verificationacademy.com/forums/u/sk7799)\
**Replies:** 2\
**Last updated:** [October 28, 2021, 10:33pm UTC](https://verificationacademy.com/forums/t/reverse-an-array-without-using-the-reverse-function/39756 "2021-10-28T22:33:51Z")

</div>

Hi, For example for an array given below, how can the elements be reversed without using the reverse() function. int array \[10\] = {15, 3, 12, 8, 8, 6, 8, 3, 4, 10}; I am thinking I can get the size/2 and start swappin…

---

## [Associative array duplicate items](https://verificationacademy.com/forums/t/associative-array-duplicate-items/39752)

<div class="topic-metadata">

**Author:** [@sk7799](https://verificationacademy.com/forums/u/sk7799)\
**Replies:** 1\
**Last updated:** [October 27, 2021, 8:31am UTC](https://verificationacademy.com/forums/t/associative-array-duplicate-items/39752 "2021-10-27T08:31:57Z")

</div>

Hi, If I have an associative array with elements {1,3,8,6,7,3} and if I want to find the duplicated elements, how many are duplicated and in what indexes, Is there an efficient way to find out rather than comparing all…

---

## [Constraint randomization for two address regions](https://verificationacademy.com/forums/t/constraint-randomization-for-two-address-regions/39355)

<div class="topic-metadata">

**Author:** [@rabh](https://verificationacademy.com/forums/u/rabh)\
**Replies:** 3\
**Last updated:** [August 5, 2021, 2:03am UTC](https://verificationacademy.com/forums/t/constraint-randomization-for-two-address-regions/39355 "2021-08-05T02:03:24Z")

</div>

I want to define two address regions such that they are non overlapping. class constraint\_eg; rand bit \[1:0\] enable; rand bit\[1:0\] \[4:0\] start\_address; rand bit \[1:0\] \[4:0\] end\_address; constraint adress{ for…

---

## [Finding repeated items in a array using array manipulation methods](https://verificationacademy.com/forums/t/finding-repeated-items-in-a-array-using-array-manipulation-methods/39399)

<div class="topic-metadata">

**Author:** [@sasi\_8985](https://verificationacademy.com/forums/u/sasi_8985)\
**Replies:** 5\
**Last updated:** [August 4, 2021, 4:33pm UTC](https://verificationacademy.com/forums/t/finding-repeated-items-in-a-array-using-array-manipulation-methods/39399 "2021-08-04T16:33:39Z")

</div>

Hi all, Hope you all are doing good in these critical days. I am having a doubt on implementing a program which finds repeated items using array manipulation methods. I tried below program. module tb; int c\[$\] = '…

---

## [Regarding class array inside another class](https://verificationacademy.com/forums/t/regarding-class-array-inside-another-class/39382)

<div class="topic-metadata">

**Author:** [@MohammedWasimMaster](https://verificationacademy.com/forums/u/MohammedWasimMaster)\
**Replies:** 6\
**Last updated:** [August 3, 2021, 9:28pm UTC](https://verificationacademy.com/forums/t/regarding-class-array-inside-another-class/39382 "2021-08-03T21:28:48Z")

</div>

Hi Team, I have a requirement where I have array of classes inside another container class. I want to print content of every element of an array when I print the container class, however that is not happening. class Re…

[Next page](https://verificationacademy.com/forums/tag/systemverilog-arrays/5944.md?match_all_tags=true&page=1&tags%5B%5D=systemverilog-Arrays)
