# Rand\_randc

**URL:** <https://verificationacademy.com/forums/t/rand-randc/35008>\
**Category:** SystemVerilog\
**Tags:** Specific-randomization-in-system-verilog-class, SystemVerilog, randc, rand\
**Created:** [September 8, 2018, 6:53am UTC](https://verificationacademy.com/forums/t/rand-randc/35008 "2018-09-08T06:53:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mahesh\_6](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/m/ecd19e/32.png) [@Mahesh\_6](https://verificationacademy.com/forums/u/Mahesh_6)\
**Post date:** [September 8, 2018, 6:53am UTC](https://verificationacademy.com/forums/t/rand-randc/35008/1 "2018-09-08T06:53:22Z")

</div>

Hi All,

Please advice the following;

1)In one of the website, they have mentioned about “rand” as;

“variables declared with rand keyword distribute values uniformly”.  
According to rand definition;  
rand bit [1:0] a;  
// a can take 0 3 1 0 or 1 3 2 2 but not all the possible values. Only cyclic random (randc) can have all possible values. Hence we can say that “variables declared with randc keyword distribute values uniformly”. ?

1. rand vs randc;  
when thinking about randc, since randc can have all possible values, like [2:0] randc can have 0 to 7 but rand [2:0] may not have all values. Hence can we can try to use randc to implement increment/decrement counter. Can we use randc in this way ?

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [September 8, 2018, 4:34pm UTC](https://verificationacademy.com/forums/t/rand-randc/35008/2 "2018-09-08T16:34:08Z")

</div>

_In reply to [Mahesh K](https://verificationacademy.com/forums/t/rand-randc/35008):_

Think about statistics. Mathematically, a uniform distribution is a number you get as the number of random solutions go to infinity. So you will get all possible values as the number of randomizations increases.

Let us take the case where you just had a single bit

```verilog
rand bit b;

```

And randomized it 10 times

1 0 1 1 0 1 0 0 1 0

So we have five 0’s and five 1’s – a perfect 50/50% distribution. But suppose we only had randomized it 4 times. We would have seen a 1/3 distribution. We are never guaranteed a 50/50 distribution, but it approaches that as we increase the number of randomizations.

When we use randc, it does guarantee a perfect distribution assuming we call randomize enough times to cover all possible solutions. With 8-bits you need to call randomize() 256 times. When you start using larger numbers, randc becomes impractical.

---

<div class="post-metadata">

**Author:** ![Mahesh\_6](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/m/ecd19e/32.png) [@Mahesh\_6](https://verificationacademy.com/forums/u/Mahesh_6)\
**Post date:** [September 8, 2018, 11:13pm UTC](https://verificationacademy.com/forums/t/rand-randc/35008/3 "2018-09-08T23:13:51Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/rand-randc/35008/2):_

Useful. Thank you Dave :)
