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


Tutorials



RANDOMIZATION METHODS

Randomization Built-In Methods



openvera has randomize(),pre_randomize() and post_randomize() built-in function for randomization.
Calling randomize() causes new values to be selected for all of the random variables in an object.
To perform operations immediately before or after randomization,pre_randomize() and post_randomize() are used.



Randomize()



Every class has a virtual predefined function randomize() ,which is provided for generating a new value.Randomization function returns 1 if the solver finds a valid solution.We cannot override this predefined function.
It is strongly recomemded to check the return value of randomize function.Constraint solver never fails after one sucessful randomization,if solution space is not changed.For every randomization call,Check the return value ,solver may fail due to dynamically changing the constraints.
In the following example,there is no solution for Var < 100 and Var > 200,so the randomization failes.
The best way to check for randomization return value is by using assertion. assert(obj.randomize());


EXAMPLE

class Simple{
rand integer Var;
constraint c { Var < 100 ; Var > 200 ; }
}
program main{
Simple obj;
obj = new();
if(obj.randomize())
printf(" Randomization sucsessfull : Var = %0d ",obj.Var);
else
printf("Randomization failed");
}

RESULTS:

Constraint failure


Pre_randomize And Post_randomize



Every class contains pre_randomize() and post_randomize() methods, which are automatically called
by randomize() before and after computing new random values.When randomize() is called,it first invokes the pre_randomize,then randomize() then if the randomization is sucesusful,then only post_randomize is invoked.


EXAMPLE:
class simple{
task pre_randomize{
printf(" PRE_RANDOMIZATION ");
}
task post_randomize{
printf(" PRE_RANDOMIZATION ");
}
}
program main{
simple obj = new();
void = obj.randomize();
}
RESULTS:

PRE_RANDOMIZATION PRE_RANDOMIZATION

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