# Can we randomize 2-D array using std::randomize()?

**URL:** <https://verificationacademy.com/forums/t/can-we-randomize-2-d-array-using-std-randomize/33384>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog, assertstdrandomizevariable, array-randomization\
**Created:** [August 5, 2017, 11:58am UTC](https://verificationacademy.com/forums/t/can-we-randomize-2-d-array-using-std-randomize/33384 "2017-08-05T11:58:24Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![ssureshgverifier](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/bcef8e/32.png) [@ssureshgverifier](https://verificationacademy.com/forums/u/ssureshgverifier)\
**Post date:** [August 6, 2017, 2:40am UTC](https://verificationacademy.com/forums/t/can-we-randomize-2-d-array-using-std-randomize/33384/3 "2017-08-06T02:40:32Z")

</div>

```verilog

//constraint u_a0 {foreach (a[i]) unique {a[i]}; } //unable to use foreach on this for some reason

```

I would prefer something like above, instead of unrolling - your simulator might support…or am I missing something ?

output for 3 loops above

a is '{'h3, 'h1, 'h0, 'h2}  
a is '{'h2, 'h0, 'h3, 'h1}  
a is '{'h0, 'h2, 'h1, 'h3}  
a is '{'h1, 'h3, 'h2, 'h0}

a is '{'h1, 'h0, 'h3, 'h2}  
a is '{'h2, 'h3, 'h1, 'h0}  
a is '{'h3, 'h2, 'h0, 'h1}  
a is '{'h0, 'h1, 'h2, 'h3}

a is '{'h3, 'h2, 'h0, 'h1}  
a is '{'h2, 'h3, 'h1, 'h0}  
a is '{'h0, 'h1, 'h2, 'h3}  
a is '{'h1, 'h0, 'h3, 'h2}

---

_[View the full topic](https://verificationacademy.com/forums/t/can-we-randomize-2-d-array-using-std-randomize/33384)._
