|HOME |ABOUT |ARTICLES |ACK |FEEDBACK |TOC |LINKS |BLOG |JOBS |


Tutorials



RANDOMIZATION

Constrained Random Verification



Openvera allowses object-oriented programiming for random stimulus generation subjected to specified constraints.
During randomization, variables declared as rand and randc inside class are only considered for randomization.Built-in randomized() method is called to generate new random values for there variable.


EXAMPLE:
class Simple{
rand integer Var;
}
program main {
Simple obj;
obj = new();
repeat(10)
if(obj.randomize())
printf(" Randomization sucsessfull : Var = %0d \n",obj.Var);
else
printf("Randomization failed\n");

}
RESULTS:

Randomization sucsessfull : Var = -2147414528
Randomization sucsessfull : Var = -1671855048
Randomization sucsessfull : Var = 1129920902
Randomization sucsessfull : Var = -1374483364
Randomization sucsessfull : Var = 1730349006
Randomization sucsessfull : Var = 1674352583
Randomization sucsessfull : Var = -485282618
Randomization sucsessfull : Var = -103324941
Randomization sucsessfull : Var = 1641506755
Randomization sucsessfull : Var = -1349564321



Random Varible Declaration:



Varibles declared as rand and randc are only randomized.All other varible are considered as state varibles.


EXAMPLE
class ex{
rand [3:0] var1;
randc [3:0] var2;
rand integer var3;
}


Fixed Arrays,dynamic arrays,associative arrays and queues can be declared as rand and randc ,all their elements are treated as rand and randc.Individual array elements can also be constrained,in this ,index expression must be constant.For dynamic arryas,the size of the array length can be constrained.Non integral data types like real are not allowed for random varible declaration.



Rand Modifier :



Variables declared with the rand keyword are standard random variables.
When ther are no other control on distrubution,these variables are uniformly distributed.
Uniformly distribution is only on the valid values.


EXAMPLE
class rand_cl{
rand bit [0:2] Var;
constraint limit_c { Var < 4;}
}
program rand_p{
rand_cl obj;
integer count_0, count_1, count_2, count_3;
count_0 = 0;count_1 = 0;count_2 = 0;count_3 = 0;
obj = new();
repeat(10000)
{
void = obj.randomize();
if( obj.Var == 0) count_0 ++;
else if( obj.Var == 1) count_1 ++;
else if( obj.Var == 2) count_2 ++;
else if( obj.Var == 3) count_3 ++;
}
printf(" count_0 = %0d , count_1 = %0d, count_2 = %0d, count_3 = %0d ",count_0, count_1, count_2, count_3);
}

RESULTS:

count_0 = 2501 , count_1 = 2553, count_2 = 2558, count_3 = 2388


Simulation results shou that the rand variable is distrubuted uniformly.

Randc Modifier :



Varibles declared as randc, randomly iterates over all the values in the range and no value is repeated with in an iteration.
Iteration sequences are not same.Bit and enumarated types can be randc variables.To reduce memory requirements, implementations can impose a limit on the maximum size of a randc variable,but it should be no less than 8 bits.


EXAMPLE
class rand_c{
randc bit [1:0]Vari;
}

program rand_cp{
rand_c obj;
integer i;
obj = new();
for(i=0;i<20;i++)
{
void = obj.randomize();
printf("%0d_",obj.Vari);
if(i%4==3)
printf("\n");
}
}

RESULTS

1_2_0_3_
3_2_0_1_
3_1_2_0_
2_0_3_1_
1_3_2_0_

Index
Introduction
Data Types
Linked List
Operators Part 1
Operators Part 2
Operators Part 3
Operator Precedence
Control Statements
Procedures And Methods
Interprocess
Fork Join
Shadow Variables
Fork Join Control
Wait Var
Event Sync
Event Trigger
Semaphore
Regions
Mailbox
Timeouts
Oop
Casting
Randomization
Randomization Methods
Constraint Block
Constraint Expression
Variable Ordaring
Aop
Predefined Methods
String Methods
Queue Methods
Dut Communication
Functional Coverage

Report a Bug or Comment on This section - Your input is what keeps Testbench.in improving with time!





<< PREVIOUS PAGE

TOP

NEXT PAGE >>

copyright 2007-2017 :: all rights reserved www.testbench.in::Disclaimer