<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://simhard.com/wiki/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://simhard.com/wiki/index.php?action=history&amp;feed=atom&amp;title=Open_Source_VHDL_Verification_Methodology%2F%D0%9E%D0%BF%D0%B8%D1%81%D0%B0%D0%BD%D0%B8%D0%B5_%D0%BF%D0%B0%D0%BA%D0%B5%D1%82%D0%B0_RandomPkg%2Fen</id>
		<title>Open Source VHDL Verification Methodology/Описание пакета RandomPkg/en - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://simhard.com/wiki/index.php?action=history&amp;feed=atom&amp;title=Open_Source_VHDL_Verification_Methodology%2F%D0%9E%D0%BF%D0%B8%D1%81%D0%B0%D0%BD%D0%B8%D0%B5_%D0%BF%D0%B0%D0%BA%D0%B5%D1%82%D0%B0_RandomPkg%2Fen"/>
		<link rel="alternate" type="text/html" href="http://simhard.com/wiki/index.php?title=Open_Source_VHDL_Verification_Methodology/%D0%9E%D0%BF%D0%B8%D1%81%D0%B0%D0%BD%D0%B8%D0%B5_%D0%BF%D0%B0%D0%BA%D0%B5%D1%82%D0%B0_RandomPkg/en&amp;action=history"/>
		<updated>2026-04-10T08:25:12Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.21.3</generator>

	<entry>
		<id>http://simhard.com/wiki/index.php?title=Open_Source_VHDL_Verification_Methodology/%D0%9E%D0%BF%D0%B8%D1%81%D0%B0%D0%BD%D0%B8%D0%B5_%D0%BF%D0%B0%D0%BA%D0%B5%D1%82%D0%B0_RandomPkg/en&amp;diff=1130&amp;oldid=prev</id>
		<title>ANA в 10:29, 16 августа 2012</title>
		<link rel="alternate" type="text/html" href="http://simhard.com/wiki/index.php?title=Open_Source_VHDL_Verification_Methodology/%D0%9E%D0%BF%D0%B8%D1%81%D0%B0%D0%BD%D0%B8%D0%B5_%D0%BF%D0%B0%D0%BA%D0%B5%D1%82%D0%B0_RandomPkg/en&amp;diff=1130&amp;oldid=prev"/>
				<updated>2012-08-16T10:29:23Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{OS-VVM TOC}}&lt;br /&gt;
=Randomization and RandomPkg=&lt;br /&gt;
&lt;br /&gt;
RandomPkg provides types subprograms and protected type methods to simplify&lt;br /&gt;
randomization. As such, it is at the heart of SynthWorks' constrained and coverage&lt;br /&gt;
driven random methodology.&lt;br /&gt;
&lt;br /&gt;
This documentation provides details on the STANDARD revision 2.0 of RandomPkg. As&lt;br /&gt;
such this documentation supercedes the slides presented in the webinar in March of&lt;br /&gt;
2009. These packages are updated from time to time and are freely available at&lt;br /&gt;
http://www.synthworks.com/downloads.&lt;br /&gt;
&lt;br /&gt;
==1. Randomization Using IEEE.math_real.uniform = Yuck!==&lt;br /&gt;
&lt;br /&gt;
A basic form of randomization can be accomplished by using the procedure uniform the&lt;br /&gt;
IEEE math_real package. However, this always results in randomization being a&lt;br /&gt;
multi-step process: call uniform to randomize a value, scale the value, and then use&lt;br /&gt;
the value.&lt;br /&gt;
&lt;br /&gt;
:{|&lt;br /&gt;
|&amp;lt;source lang=&amp;quot;vhdl&amp;quot;&amp;gt;&lt;br /&gt;
RandomGenProc : process&lt;br /&gt;
  variable RandomVal : real ; -- Random value&lt;br /&gt;
  variable DataSent : integer ;&lt;br /&gt;
  variable seed1 : positive := 7 ; -- initialize seeds&lt;br /&gt;
  variable seed2 : positive := 1 ;&lt;br /&gt;
begin&lt;br /&gt;
  for i in 0 to 255*6 loop&lt;br /&gt;
    uniform(seed1, seed2, RandomVal) ; -- randomize 0.0 to 1.0&lt;br /&gt;
    DataSent := integer(trunc(RandomVal*256.0)) ; -- scale to 0 to 255&lt;br /&gt;
    do_transaction(…, DataSent, …) ;&lt;br /&gt;
    . . .&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Optimally we would like to be able to call a function to do this so we can do this all in&lt;br /&gt;
one step. Unfortunately we cannot write a normal VHDL function since we need to&lt;br /&gt;
read and update the seed as well as return a randomized value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==2. Simplifying Randomization==&lt;br /&gt;
&lt;br /&gt;
RandomPkg uses a protected type, named RandomPType, to encapsulate the seed.&lt;br /&gt;
Within a protected type, impure functions can read and update the seed as well as&lt;br /&gt;
return a randomized value. To randomize values using the protected type, declare a&lt;br /&gt;
variable of type RandomPType, initialze the seed, and randomize values.&lt;br /&gt;
&lt;br /&gt;
::{|&lt;br /&gt;
|&amp;lt;source lang=&amp;quot;vhdl&amp;quot;&amp;gt;&lt;br /&gt;
RandomGenProc : process&lt;br /&gt;
  variable RV : RandomPType ; -- protected type from RandomPkg&lt;br /&gt;
begin&lt;br /&gt;
  RV.InitSeed (RV'instance_name) ; -- Generate initial seeds&lt;br /&gt;
  for i in 0 to 255*6 loop&lt;br /&gt;
    do_transaction(…, RV.RandInt(0, 255), …) ; -- random value between 0 and 255&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Note the calls to protected type methods (subprograms) include the protected type&lt;br /&gt;
variable (RV) within the call (such as RV.RandInt(0, 255)).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==3. Manipulating the Seeds==&lt;br /&gt;
&lt;br /&gt;
With protected types internal objects are private and accessible only through methods.&lt;br /&gt;
The internal representation of the seed has a valid initial value, however, to ensure that&lt;br /&gt;
each process' randomization is independent of each other, it is important to give each&lt;br /&gt;
seed to a different initial value. As a result for a test that uses more than one&lt;br /&gt;
randomization variable, initialize each seed once - if there is only one randomization&lt;br /&gt;
variable, there is no need to initialize the seed.&lt;br /&gt;
&lt;br /&gt;
The method InitSeed converts its argument value to RandomSeedType (the internal&lt;br /&gt;
representation of the seed) and stores the value within the protected type. InitSeed is&lt;br /&gt;
overloaded to accept either string or integer values. The preferred way to give each&lt;br /&gt;
seed a unique value is pass the string value, RV'instance_name.&lt;br /&gt;
&lt;br /&gt;
:{|&lt;br /&gt;
|&amp;lt;source lang=&amp;quot;vhdl&amp;quot;&amp;gt;&lt;br /&gt;
RV.InitSeed (RV'instance_name) ;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The methods GetSeed and SetSeed are used to read and restore a seed value. The&lt;br /&gt;
declarations for these are shown below.&lt;br /&gt;
&lt;br /&gt;
:{|&lt;br /&gt;
|&amp;lt;source lang=&amp;quot;vhdl&amp;quot;&amp;gt;&lt;br /&gt;
impure function GetSeed return RandomSeedType ;&lt;br /&gt;
procedure SetSeed (RandomSeedIn : RandomSeedType ) ;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The function to_string and procedures write and read are used to write and read values&lt;br /&gt;
of type RandomSeedType. The declarations for these subprograms are shown below.&lt;br /&gt;
Note these are in RandomBasePkg.vhd and are separate from the protected type.&lt;br /&gt;
&lt;br /&gt;
:{|&lt;br /&gt;
|&amp;lt;source lang=&amp;quot;vhdl&amp;quot;&amp;gt;&lt;br /&gt;
function to_string(A : RandomSeedType) return string ;&lt;br /&gt;
procedure write(L: inout line ; A : RandomSeedType ) ;&lt;br /&gt;
procedure read (L: inout line ; A : out RandomSeedType ; good : out boolean ) ;&lt;br /&gt;
procedure read (L: inout line ; A : out RandomSeedType ) ;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For a long test, it may be advantageous to read the seed periodically and print it out.&lt;br /&gt;
If a failure or other interesting condition is generated, the seed may be restored to a&lt;br /&gt;
value that was recorded near the failure with the intent of generating the error quickly&lt;br /&gt;
to assist with debug.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 4. Basic Randomization ==&lt;br /&gt;
&lt;br /&gt;
The basic randomization generates an integer value that is either within some range or&lt;br /&gt;
within a set of values. The set of values and exclude values are all of type&lt;br /&gt;
integer_vector (defined in VHDL-2008). The examples below show the basic&lt;br /&gt;
randomization overloading. When a value of integer_vector is specifed, the extra set of&lt;br /&gt;
parentheses denote that it is an aggregate value.&lt;br /&gt;
&lt;br /&gt;
:{|&lt;br /&gt;
|&amp;lt;source lang=&amp;quot;vhdl&amp;quot;&amp;gt;&lt;br /&gt;
RandomGenProc : process&lt;br /&gt;
  variable RV : RandomPType ; -- protected type from RandomPkg&lt;br /&gt;
  variable DataInt : integer ;&lt;br /&gt;
begin&lt;br /&gt;
  RV.InitSeed (RV'instance_name) ; -- Generate initial seeds&lt;br /&gt;
  -- Generate a value in range 0 to 255&lt;br /&gt;
  DataInt := RV.RandInt(0, 255) ;&lt;br /&gt;
  . . .&lt;br /&gt;
  -- Generate a value in range 1 to 9 except exclude values 2,4,6,8&lt;br /&gt;
  DataInt := RV.RandInt(1, 9, (2,4,6,8)) ;&lt;br /&gt;
  . . .&lt;br /&gt;
  -- Generate a value in set 1,3,5,7,9&lt;br /&gt;
  DataInt := RV.RandInt( (1,3,7,9) ) ; -- note two sets of parens required&lt;br /&gt;
  . . .&lt;br /&gt;
  -- Generate a value in set 1,3,5,7,9 except exclude values 3,7&lt;br /&gt;
  DataInt := RV.RandInt((1,3,7,9), (3,7) ) ;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
These same functions are available for types std_logic_vector(RandSlv), unsigned&lt;br /&gt;
(RandUnsigned) and signed (RandSigned). Note that parameter values are still&lt;br /&gt;
specified as integers and there is an additional value used to specify the size of the&lt;br /&gt;
value to generate. For example, the following call to RandSlv defines the array size to&lt;br /&gt;
be 8 bits.&lt;br /&gt;
&lt;br /&gt;
:{|&lt;br /&gt;
|&amp;lt;source lang=&amp;quot;vhdl&amp;quot;&amp;gt;&lt;br /&gt;
. . .&lt;br /&gt;
variable DataSlv : std_logic_vector(7 downto 0) ;&lt;br /&gt;
begin&lt;br /&gt;
  . . .&lt;br /&gt;
  -- Generate a value in range 0 to 255&lt;br /&gt;
  DataSlv := RV.RandSlv(0, 255, 8) ;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For randomizing within a range, there is also a RandReal function. Like procedure&lt;br /&gt;
Uniform, it never generates its end values.&lt;br /&gt;
The overloading for the RandInt functions is as follows.&lt;br /&gt;
&lt;br /&gt;
:{|&lt;br /&gt;
|&amp;lt;source lang=&amp;quot;vhdl&amp;quot;&amp;gt;&lt;br /&gt;
impure function RandInt (Min, Max : integer) return integer ;&lt;br /&gt;
impure function RandInt (Min, Max: integer; Exclude: integer_vector) return integer;&lt;br /&gt;
impure function RandInt ( A : integer_vector ) return integer ;&lt;br /&gt;
impure function RandInt ( A : integer_vector; Exclude: integer_vector) return integer;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 5. Weighted Randomization ==&lt;br /&gt;
&lt;br /&gt;
A weighted distribution randomly generates each of set of values a specified percentage&lt;br /&gt;
of the time. RandomPType provides a weighted distribution that specifies a value and&lt;br /&gt;
its weight (DistValInt) and one that only specifies weights (DistInt).&lt;br /&gt;
DistValInt is called with an array of value pairs. The first item in the pair is the value&lt;br /&gt;
and the second is the weight. The frequency that each value will occur is weight/(sum&lt;br /&gt;
of weights). As a result, in the following call to DistValInt, the likelihood of a 1 to&lt;br /&gt;
occur is 7/10 times or 70%. The likelihood of 3 is 20% and 5 is 10%.&lt;br /&gt;
&lt;br /&gt;
:{|&lt;br /&gt;
|&amp;lt;source lang=&amp;quot;vhdl&amp;quot;&amp;gt;&lt;br /&gt;
variable RV : RandomPType ;&lt;br /&gt;
. . .&lt;br /&gt;
DataInt := RV.DistValInt( ((1, 7), (3, 2), (5, 1)) ) ;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
DistInt is a simplified version of DistValInt that only specifies weights. The values&lt;br /&gt;
generated are 0 to N-1 where N is the number of weights specified. As a result, the&lt;br /&gt;
following call to DistInt the likelihood of a 0 is 70%, 1 is 20% and 2 is 10%.&lt;br /&gt;
&lt;br /&gt;
:{|&lt;br /&gt;
|&amp;lt;source lang=&amp;quot;vhdl&amp;quot;&amp;gt;&lt;br /&gt;
variable RV : RandomPType ;&lt;br /&gt;
. . .&lt;br /&gt;
DataInt := RV.DistValInt( ((7, 2, 1)) ;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 6. Usage ==&lt;br /&gt;
&lt;br /&gt;
Each randomization result is produced by a function and that result can be used directly&lt;br /&gt;
in an expression. Hence, we can randomize a delay that is between 3 and 10 clocks.&lt;br /&gt;
&lt;br /&gt;
:{|&lt;br /&gt;
|&amp;lt;source lang=&amp;quot;vhdl&amp;quot;&amp;gt;&lt;br /&gt;
wait for RV.RandInt(3, 10) * tperiod_Clk - tpd ;&lt;br /&gt;
wait until Clk = '1' ;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The values can also be used directly inside a case statement. The following example&lt;br /&gt;
uses DistInt to generate the first case target 70% of the time, the second 20%, and the&lt;br /&gt;
third 10%.&lt;br /&gt;
&lt;br /&gt;
:{|&lt;br /&gt;
|&amp;lt;source lang=&amp;quot;vhdl&amp;quot;&amp;gt;&lt;br /&gt;
variable RV : RandomPType ;&lt;br /&gt;
. . .&lt;br /&gt;
StimGen : while TestActive loop -- Repeat until done&lt;br /&gt;
  case RV.DistInt( (7, 2, 1) ) is&lt;br /&gt;
    when 0 =&amp;gt; -- Normal Handling -- 70%&lt;br /&gt;
    . . .&lt;br /&gt;
    when 1 =&amp;gt; -- Error Case 1 -- 20%&lt;br /&gt;
    . . .&lt;br /&gt;
    when 2 =&amp;gt; -- Error Case 2 -- 10%&lt;br /&gt;
    . . .&lt;br /&gt;
    when others =&amp;gt;&lt;br /&gt;
      report &amp;quot;DistInt&amp;quot; severity failure ; -- Signal bug in DistInt&lt;br /&gt;
  end case ;&lt;br /&gt;
end loop ;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following code segment generates the transactions for writing to&lt;br /&gt;
DMA_WORD_COUNT, DMA_ADDR_HI, and DMA_ADDR_LO in a random order that is&lt;br /&gt;
different every time this code segment is run. The sequence finishes with a write to&lt;br /&gt;
DMA_CTRL. When DistInt is called with a weight of 0, the corresponding value does&lt;br /&gt;
not get generated. Hence by initializing all of the weights to 1 and then setting it to 0&lt;br /&gt;
when it is selected, each case target only occurs once. The &amp;quot;for loop&amp;quot; loops three times&lt;br /&gt;
to allow each transaction to be selected.&lt;br /&gt;
&lt;br /&gt;
:{|&lt;br /&gt;
|&amp;lt;source lang=&amp;quot;vhdl&amp;quot;&amp;gt;&lt;br /&gt;
variable RV : RandomPType ;&lt;br /&gt;
. . .&lt;br /&gt;
Wt0 := 1; Wt1 := 1; Wt2 := 1; -- Initial Weights&lt;br /&gt;
for i in 1 to 3 loop -- Loop 1x per transaction&lt;br /&gt;
  case RV.DistInt( (Wt0, Wt1, Wt2) ) is -- Select transaction&lt;br /&gt;
    when 0 =&amp;gt; -- Transaction 0&lt;br /&gt;
      CpuWrite(CpuRec, DMA_WORD_COUNT, DmaWcIn);&lt;br /&gt;
      Wt0 := 0 ; -- remove from randomization&lt;br /&gt;
    when 1 =&amp;gt; -- Transaction 1&lt;br /&gt;
      CpuWrite(CpuRec, DMA_ADDR_HI, DmaAddrHiIn);&lt;br /&gt;
      Wt1 := 0 ; -- remove from randomization&lt;br /&gt;
    when 2 =&amp;gt; -- Transaction 2&lt;br /&gt;
      CpuWrite(CpuRec, DMA_ADDR_LO, DmaAddrLoIn);&lt;br /&gt;
      Wt2 := 0 ; -- remove from randomization&lt;br /&gt;
    when others =&amp;gt; report &amp;quot;DistInt&amp;quot; severity failure ;&lt;br /&gt;
  end case ;&lt;br /&gt;
end loop ;&lt;br /&gt;
CpuWrite(CpuRec, DMA_CTRL, START_DMA or DmaCycle);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following code segment uses an exclude list to keep from repeating the last value.&lt;br /&gt;
Note when passing an integer value to an integer_vector parameter, an aggregate&lt;br /&gt;
using named association &amp;quot;(0=&amp;gt; LastDataInt)&amp;quot; is used to denote a single element array.&lt;br /&gt;
Note that during the first execution of this process, LastDataInt has the value&lt;br /&gt;
integer'left (a very small number), which is outside the range 0 to 255, and as a result,&lt;br /&gt;
has no impact on the randomization.&lt;br /&gt;
&lt;br /&gt;
:{|&lt;br /&gt;
|&amp;lt;source lang=&amp;quot;vhdl&amp;quot;&amp;gt;&lt;br /&gt;
RandomGenProc : process&lt;br /&gt;
  variable RV : RandomPType ;&lt;br /&gt;
  variable DataInt, LastDataInt : integer ;&lt;br /&gt;
begin&lt;br /&gt;
  . . .&lt;br /&gt;
  DataInt := RV.RandInt(0, 255, (0 =&amp;gt; LastDataInt)) ;&lt;br /&gt;
  LastDataInt := DataInt;&lt;br /&gt;
  . . .&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following code segment uses an exclude list to keep from repeating the four&lt;br /&gt;
previous values.&lt;br /&gt;
&lt;br /&gt;
:{|&lt;br /&gt;
|&amp;lt;source lang=&amp;quot;vhdl&amp;quot;&amp;gt;&lt;br /&gt;
RandProc : process&lt;br /&gt;
  variable RV : RandomPtype ;&lt;br /&gt;
  variable DataInt : integer ;&lt;br /&gt;
  variable Prev4DataInt : integer_vector(3 downto 0) := (others =&amp;gt; integer'low) ;&lt;br /&gt;
begin&lt;br /&gt;
  . . .&lt;br /&gt;
  DataInt := RV.RandInt(0, 100, Prev4DataInt) ;&lt;br /&gt;
  Prev4DataInt := Prev4DataInt(2 downto 0) &amp;amp; DataInt ;&lt;br /&gt;
  . . .&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 7. Creating a Test ==&lt;br /&gt;
&lt;br /&gt;
Creating tests is all about methodology. SynthWorks' methodology marries&lt;br /&gt;
randomization subprograms (from RandomPkg) and functional coverage subprograms&lt;br /&gt;
(from CoveragePkg - also freely available at http://www.synthworks.com/downloads)&lt;br /&gt;
with VHDL programming constructs. Each test sequence is derived by randomly&lt;br /&gt;
selecting either branches of code or values for operations. Randomization constraints&lt;br /&gt;
are created using normal sequential coding techniques (such as nesting of case, if,&lt;br /&gt;
loop, and assignment statements). This approach is simple yet powerful. Since all of&lt;br /&gt;
the code is sequential, randomized sequences are readily mixed with directed and&lt;br /&gt;
algorithmic sequences.&lt;br /&gt;
&lt;br /&gt;
A simple demonstration of randomizing is the following test which uses heuristics&lt;br /&gt;
(guesses) at length of bursts of data and delays between bursts of data to&lt;br /&gt;
randomization traffic being sent to a FIFO.&lt;br /&gt;
&lt;br /&gt;
:{|&lt;br /&gt;
|&amp;lt;source lang=&amp;quot;vhdl&amp;quot;&amp;gt;&lt;br /&gt;
variable RV : RandomPType ;&lt;br /&gt;
. . .&lt;br /&gt;
TxStimGen : while TestActive loop&lt;br /&gt;
  -- Burst between 1 and 10 values&lt;br /&gt;
  BurstLen := RV.RandInt(Min =&amp;gt; 1, Max =&amp;gt; 10);&lt;br /&gt;
  for i in 1 to BurstLen loop&lt;br /&gt;
    DataSent := DataSent + 1 ;&lt;br /&gt;
    WriteToFifo(DataSent) ;&lt;br /&gt;
  end loop ;&lt;br /&gt;
  -- Delay between bursts: (BurstLen &amp;lt;=3: 1-6, &amp;gt;3: 3-10)&lt;br /&gt;
  if BurstLen &amp;lt;= 3 then&lt;br /&gt;
    BurstDelay := RV.RandInt(1, 6) ; -- small burst, small delay&lt;br /&gt;
  else&lt;br /&gt;
    BurstDelay := RV.RandInt(3, 10) ; -- bigger burst, bugger delay&lt;br /&gt;
  end if ;&lt;br /&gt;
  wait for BurstDelay * tperiod_Clk - tpd ;&lt;br /&gt;
  wait until Clk = '1' ;&lt;br /&gt;
end loop TxStimGen ;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Functional coverage counts which test cases have been generated and give engineers&lt;br /&gt;
an indication of when testing is done. This is essential when using randomization to&lt;br /&gt;
create a test as otherwise there is no way to know what the test actually did.&lt;br /&gt;
Functional coverage can be implemented using subprogram calls (either custom or from&lt;br /&gt;
the CoveragePkg) or VHDL code. Functional coverage is stored in signals and can be&lt;br /&gt;
used to change the randomization (either directly as a constraint or indirectly as&lt;br /&gt;
something that contributes to changing a constraint) to generate missing coverage&lt;br /&gt;
items.&lt;br /&gt;
With a FIFO, we need to see lots of write attempts while full and read attempts while&lt;br /&gt;
empty. One thing we can do to improve the previous test is to increase or decrease&lt;br /&gt;
the burst length and delay based on the number of write attempts while full or read&lt;br /&gt;
attempts while empty we have seen. To explore how to generate the coverage, see&lt;br /&gt;
the CoveragePkg documentation.&lt;br /&gt;
&lt;br /&gt;
For a design for which has numerous conditions we need to generate, we can do&lt;br /&gt;
coverage on the input stimulus and then randomly select one of the uncovered&lt;br /&gt;
conditions as the next transaction to be generated.&lt;br /&gt;
&lt;br /&gt;
Solutions for the two previous coverage driven randomization problems are provided in&lt;br /&gt;
SynthWorks' VHDL Testbenches and Verification class.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 8. Random Stability ==&lt;br /&gt;
&lt;br /&gt;
A protected type is always used with a variable object. If the object is declared in a&lt;br /&gt;
process, it is a regular variable. If the object is declared in an architecture, then it is&lt;br /&gt;
declared as a shared variable.&lt;br /&gt;
&lt;br /&gt;
All of the examples in this document show RandomPType being defined in a process as&lt;br /&gt;
a regular variable. This is done to ensure random stability. Random stability is the&lt;br /&gt;
ability to re-run a test and get exactly the same sequence. Random stability is required&lt;br /&gt;
for verification since if we find a failure and then fix it, if the same sequence is not&lt;br /&gt;
generated, we will not know the fix actually worked.&lt;br /&gt;
&lt;br /&gt;
Random stability is lost when a randomization variable is declared as a shared variable&lt;br /&gt;
in an architecture and shared among multiple processes. When a randomization&lt;br /&gt;
variable is shared, the seed is shared. Each randomization reads and updates the seed.&lt;br /&gt;
If the processes accessing the shared variable run during the same delta cycle, then the&lt;br /&gt;
randomization of the test depends on the order of which RandomPType is accessed.&lt;br /&gt;
This order can change anytime the design is optimized - which will happen after fixing&lt;br /&gt;
bugs. As a result, the test is unstable.&lt;br /&gt;
&lt;br /&gt;
To ensure stability, create a separate variable for randomization in each process.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 9. Other Distributions ==&lt;br /&gt;
&lt;br /&gt;
By default, all randomizations use a uniform distribution. In addition to uniform&lt;br /&gt;
distributions, RandomPType also provides distributions for favor_small, favor_big,&lt;br /&gt;
normal, and poisson. The following is the overloading for these functions.&lt;br /&gt;
&lt;br /&gt;
:{|&lt;br /&gt;
|&amp;lt;source lang=&amp;quot;vhdl&amp;quot;&amp;gt;&lt;br /&gt;
-- Generate values, each with an equal probability&lt;br /&gt;
impure function Uniform (Min, Max : in real) return real ;&lt;br /&gt;
impure function Uniform (Min, Max : integer) return integer ;&lt;br /&gt;
impure function Uniform (Min, Max : integer ; Exclude: integer_vector) return integer ;&lt;br /&gt;
-- Generate more small numbers than big&lt;br /&gt;
impure function Favor_small (Min, Max : real) return real ;&lt;br /&gt;
impure function Favor_small (Min, Max : integer) return integer ;&lt;br /&gt;
impure function Favor_small(Min, Max: integer; Exclude: integer_vector) return integer ;&lt;br /&gt;
-- Generate more big numbers than small&lt;br /&gt;
impure function Favor_big (Min, Max : real) return real ;&lt;br /&gt;
impure function Favor_big (Min, Max : integer) return integer ;&lt;br /&gt;
impure function Favor_big (Min, Max : integer ; Exclude: integer_vector) return integer ;&lt;br /&gt;
-- Generate normal = gaussian distribution&lt;br /&gt;
impure function Normal (Mean, StdDeviation : real) return real ;&lt;br /&gt;
impure function Normal (Mean, StdDeviation, Min, Max : real) return real ;&lt;br /&gt;
impure function Normal (Mean : real ;&lt;br /&gt;
                        StdDeviation : real ;&lt;br /&gt;
                        Min : integer ;&lt;br /&gt;
                        Max : integer ;&lt;br /&gt;
                        Exclude : integer_vector := NULL_INTV&lt;br /&gt;
                       ) return integer ;&lt;br /&gt;
-- Generate poisson distribution&lt;br /&gt;
impure function Poisson (Mean : real) return real ;&lt;br /&gt;
impure function Poisson (Mean, Min, Max : real) return real ;&lt;br /&gt;
impure function Poisson (&lt;br /&gt;
                         Mean : real ;&lt;br /&gt;
                         Min : integer ;&lt;br /&gt;
                         Max : integer ;&lt;br /&gt;
                         Exclude : integer_vector := NULL_INTV&lt;br /&gt;
                        ) return integer ;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The package also provides experimental mechanisms for changing the distributions&lt;br /&gt;
used with functions RandInt, RandSlv, RandUnsigned, and RandSigned.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 10. Compiling RandomPkg and Friends ==&lt;br /&gt;
&lt;br /&gt;
The core package is RandomPkg. It is supported by the packages RandomBasePkg and&lt;br /&gt;
SortListPkg_int. We compile all of our packages into a library named SynthWorks.&lt;br /&gt;
Directions for compiling these packages using either VHDL-2008 or VHDL-2002 are&lt;br /&gt;
provided in the separate document, README_RandomPkg.pdf.&lt;br /&gt;
Your programs will need to reference RandomPkg. If your programs need to use IO for&lt;br /&gt;
the seed (to_string, write, read), then you will also need to include RandomBasePkg.&lt;br /&gt;
&lt;br /&gt;
:{|&lt;br /&gt;
|&amp;lt;source lang=&amp;quot;vhdl&amp;quot;&amp;gt;&lt;br /&gt;
library SynthWorks ;&lt;br /&gt;
use SynthWorks.RandomPkg.all ;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 11. Future Work ==&lt;br /&gt;
&lt;br /&gt;
RandomPkg.vhd is a work in progress and will be updated from time to time.&lt;br /&gt;
In addition to the RandomPkg, we also are freely distributing our coverage package,&lt;br /&gt;
CoveragePkg. See http://www.SynthWorks.com/downloads. Over time we will also be&lt;br /&gt;
releasing other packages that we currently distribute with our classes (such as&lt;br /&gt;
scoreboards and memory modeling) and hope to convince simulation vendors to&lt;br /&gt;
distribute our libraries with their tools.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 12. About SynthWorks ==&lt;br /&gt;
&lt;br /&gt;
SynthWorks' VHDL training can help you jumpstart your VHDL design and verification&lt;br /&gt;
tasks. Whether it be introductory, verification or synthesis training, the knowledge you&lt;br /&gt;
gain will help you finish your next FPGA or ASIC project in a more timely and efficient&lt;br /&gt;
manner.&lt;br /&gt;
&lt;br /&gt;
We provide training in leading edge VHDL verification techniques, including transactionbased&lt;br /&gt;
testing, bus functional modeling, self-checking, data structures (linked-lists,&lt;br /&gt;
scoreboards, memories), directed, algorithmic, constrained random, and coverage&lt;br /&gt;
driven random testing, and functional coverage. In addition to RandomPkg, our&lt;br /&gt;
verification class comes with packages for functional coverage, memories, scoreboards,&lt;br /&gt;
and interfaces.&lt;br /&gt;
&lt;br /&gt;
Help support our open source packages by buying your VHDL training from&lt;br /&gt;
SynthWorks.&lt;br /&gt;
&lt;br /&gt;
== 13. About the Author ==&lt;br /&gt;
&lt;br /&gt;
Jim Lewis, the founder of SynthWorks, has twenty-six years of design, teaching, and&lt;br /&gt;
problem solving experience. In addition to working as a Principal Trainer for&lt;br /&gt;
SynthWorks, Mr Lewis has done ASIC and FPGA design, custom model development,&lt;br /&gt;
and consulting. Mr Lewis is an active member of the VHDL standards effort and is the&lt;br /&gt;
current IEEE VHDL Study Group chair.&lt;br /&gt;
I am passionate about the use of VHDL for verification. If you find any innovative&lt;br /&gt;
usage for the package, let us know. If you find bugs with any of SynthWorks' packages&lt;br /&gt;
or would like to request enhancements, you can reach me at jim@synthworks.com.&lt;br /&gt;
&lt;br /&gt;
[[Категория:OS-VVM]]&lt;/div&gt;</summary>
		<author><name>ANA</name></author>	</entry>

	</feed>