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”. ?
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 ?
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
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.