Verification Academy

Search form

My Account Menu

  • Register
  • Log In
  • Topics
  • Courses
  • Forums
  • Patterns Library
  • Cookbooks
  • Events
  • More
  • All Topics
    The Verification Academy offers users multiple entry points to find the information they need. One of these entry points is through Topic collections. These topics are industry standards that all design and verification engineers should recognize. While we continue to add new topics, users are encourage to further refine collection information to meet their specific interests.
    • Languages & Standards

      • Portable Test and Stimulus
      • Functional Safety
      • Design & Verification Languages
    • Methodologies

      • UVM - Universal Verification Methodology
      • UVM Framework
      • UVM Connect
      • FPGA Verification
      • Coverage
    • Techniques & Tools

      • Verification IP
      • Simulation-Based Techniques
      • Planning, Measurement, and Analysis
      • Formal-Based Techniques
      • Debug
      • Clock-Domain Crossing
      • Acceleration
  • All Courses
    The Verification Academy is organized into a collection of free online courses, focusing on various key aspects of advanced functional verification. Each course consists of multiple sessions—allowing the participant to pick and choose specific topics of interest, as well as revisit any specific topics for future reference. After completing a specific course, the participant should be armed with enough knowledge to then understand the necessary steps required for maturing their own organization’s skills and infrastructure on the specific topic of interest. The Verification Academy will provide you with a unique opportunity to develop an understanding of how to mature your organization’s processes so that you can then reap the benefits that advanced functional verification offers.
    • Universal Verification Methodology (UVM)

      • Advanced UVM
      • Basic UVM
      • Introduction to UVM
      • UVM Connect
      • UVM Debug
      • UVMF - One Bite at a Time
    • Featured Courses

      • Introduction to ISO 26262
      • Introduction to DO-254
      • Clock-Domain Crossing Verification
      • Portable Stimulus Basics
      • Power Aware CDC Verification
      • Power Aware Verification
      • SystemVerilog OOP for UVM Verification
    • Additional Courses

      • Assertion-Based Verification
      • An Introduction to Unit Testing with SVUnit
      • Evolving FPGA Verification Capabilities
      • Metrics in SoC Verification
      • SystemVerilog Testbench Acceleration
      • Testbench Co-Emulation: SystemC & TLM-2.0
      • Verification Planning and Management
      • VHDL-2008 Why It Matters
    • Formal-Based Techniques

      • Formal Assertion-Based Verification
      • Formal-Based Technology: Automatic Formal Solutions
      • Formal Coverage
      • Getting Started with Formal-Based Technology
      • Handling Inconclusive Assertions in Formal Verification
      • Sequential Logic Equivalence Checking
    • Analog/Mixed Signal

      • AMS Design Configuration Schemes
      • Improve AMS Verification Performance
      • Improve AMS Verification Quality
  • All Forum Topics
    The Verification Community is eager to answer your UVM, SystemVerilog and Coverage related questions. We encourage you to take an active role in the Forums by answering and commenting to any questions that you are able to.
    • UVM Forum

      • Active Questions
      • Solutions
      • Replies
      • No Replies
      • Search
      • UVM Forum
    • SystemVerilog Forum

      • Active Questions
      • Solutions
      • Replies
      • No Replies
      • Search
      • SystemVerilog Forum
    • Coverage Forum

      • Active Questions
      • Solutions
      • Replies
      • No Replies
      • Search
      • Coverage Forum
    • Additional Forums

      • Announcements
      • Downloads
      • OVM Forum
  • Patterns Library
    The Verification Academy Patterns Library contains a collection of solutions to many of today's verification problems. The patterns contained in the library span across the entire domain of verification (i.e., from specification to methodology to implementation—and across multiple verification engines such as formal, simulation, and emulation).
    • Implementation Patterns

      • Environment Patterns
      • Stimulus Patterns
      • Analysis Patterns
      • All Implementation Patterns
    • Specification Patterns

      • Occurrence Property Patterns
      • Order Property Patterns
      • All Specification Patterns
    • Pattern Resources

      • Start Here - Patterns Library Overview
      • Whitepaper - Taking Reuse to the Next Level
      • Verification Horizons - The Verification Academy Patterns Library
      • Contribute a Pattern to the Library
  • All Cookbooks
    Find all the methodology you need in this comprehensive and vast collection. The UVM and Coverage Cookbooks contain dozens of informative, executable articles covering all aspects of UVM and Coverage.
    • UVM Cookbook

      • UVM Basics
      • Testbench Architecture
      • DUT-Testbench Connections
      • Configuring a Test Environment
      • Analysis Components & Techniques
      • End Of Test Mechanisms
      • Sequences
      • The UVM Messaging System
      • Other Stimulus Techniques
      • Register Abstraction Layer
      • Testbench Acceleration through Co-Emulation
      • Debug of SV and UVM
      • UVM Connect - SV-SystemC interoperability
      • UVM Versions and Compatibility
      • UVM Cookbook
    • Coding Guidelines & Deployment

      • Code Examples
      • UVM Verification Component
      • Package/Organization
      • Questa/Compiling UVM
      • SystemVerilog Guidelines
      • SystemVerilog Performance Guidelines
      • UVM Guidelines
      • UVM Performance Guidelines
    • Coverage Cookbook

      • Introduction
      • What is Coverage?
      • Kinds of Coverage
      • Specification to Testplan
      • Testplan to Functional Coverage
      • Bus Protocol Coverage
      • Block Level Coverage
      • Datapath Coverage
      • SoC Coverage Example
      • Requirements Writing Guidelines
      • Coverage Cookbook
  • All Events
    No one argues that the challenges of verification are growing exponentially. What is needed to meet these challenges are tools, methodologies and processes that can help you transform your verification environment. These recorded seminars from Verification Academy trainers and users provide examples for adoption of new technologies and how to evolve your verification process.
    • Upcoming & Featured Events

      • CDC+RDC Analysis - 4/20
      • Low Power Verification - 4/29
      • Fault Campaign for Mixed-Signal - 5/4
      • User2User - 5/26
      • Webinar Calendar
    • On-Demand Webinars

      • Basic Abstraction Techniques
      • Safety Analysis Techniques
      • QVIP Workflow and Debug for PCIe
      • Writing a Proxy-driven Testbench
      • Achieving High Defect Coverage
      • Visualizer Features
      • Questa Static and Formal Apps
      • All On-Demand Webinars
    • Recording Archive

      • Siemens EDA 2021 Functional Verification Webinar Series
      • Improving Your SystemVerilog & UVM Skills
      • Should I Kill My Formal Run?
      • Visualizer Debug Environment
      • Industry Data & Surveys
      • All Recordings
    • Conferences

      • DVCon 2021
      • DVCon 2020
      • DAC 2019
      • All Conferences
    • Mentor Learning Center

      • SystemVerilog Fundamentals
      • SystemVerilog UVM
      • View all Learning Paths
  • About Verification Academy
    The Verification Academy will provide you with a unique opportunity to develop an understanding of how to mature your organization's processes so that you can then reap the benefits that advanced functional verification offers.
    • Blog & News

      • Verification Horizons Blog
      • Academy News
      • Academy Newsletter
      • Technical Resources
    • Verification Horizons Publication

      • Verification Horizons - March 2021
      • Verification Horizons - November 2020
      • Verification Horizons - July 2020
      • Issue Archive
    • About Us

      • Verification Academy Overview
      • Subject Matter Experts
      • Contact Us
    • Training

      • Questa Basic
      • Questa Advanced
      • Mastering Questa
Ask a Question
SystemVerilog
  • Home
  • Forums
  • SystemVerilog
  • distributed weightage constraint

distributed weightage constraint

SystemVerilog 5096
Hani John Poly
Hani John Poly
Full Access
3 posts
August 28, 2013 at 3:09 am

Hello,

I need to randomize a variable with equal distribution between {1 , [2:5], [6:15]}
ie, probability to generate 1 is 1/3
probability to generate 2..5 is 1/3
probability to generate 6..15 is 1/3

How do i define this in sv?

Below is the code i tried, but the distribution were not same for different seeds.

class constraint_c;
 
  rand bit[3:0]  ack_delay;
 
  constraint ack_delay_constr { ack_delay dist {1 := 1, [2:5] :/ 1, [6:15] :/ 1}; }
 
  function void post_randomize();
    $display("ack_delay %d", ack_delay);
  endfunction
endclass
 
module test_constraint();
 
  constraint_c   cl;
 
  initial
  begin
    cl = new();
    repeat (6) 
    begin
      cl.randomize();
    end
 
    $finish();
  end
 
endmodule

Regards, Hani

Replies

Log In to Reply
Ch Sasikanth
Ch Sasikanth
Full Access
1 post
August 28, 2013 at 7:09 am

Hello John,
For equal distribution for the above three ranges 1, [2:5] , [6:15] you have to use constraint as

"ack_delay_constr { ack_delay dist {1 := 1, [2:5] :/ 4, [6:15] :/ 10}; }"

For getting stable distribution you have to use the same seed. And the distribution will be almost same in the long repeats, but not for the small repeats. For different seeds the random distribution order will be different, but for the same seed distribution order will be same.

Regards,
Sasi

dave_59
dave_59
Forum Moderator
8746 posts
August 28, 2013 at 4:22 pm

In reply to Ch Sasikanth :

The original example was modeled correctly. :/ applies the weight to the range as a whole. The constraint that Sasi wrote would give a uniform distribution to each value in the range.

For a large enough number of randomization calls, it should not matter if the seed is the same or different. How many calls did you make?

— Dave Rich, Verification Architect, Siemens EDA

Hani John Poly
Hani John Poly
Full Access
3 posts
August 30, 2013 at 1:53 am

In reply to dave_59:

The program was with 6 iterations. If i increase the samples, weighted distribution works better.

The example posted can be considered as a testcase, that is required to cover 3 sets.
So i defined the testcase to randomize 2*(number of sets)times.

If i consider randc,
randc bit [2:0] cnt;
"cnt" is guaranteed to have different randomized value, and 1 testcase with 8 iterations of randomization is going to cover all the possibilities.

Using weighted distribution, How do we come up with a similar figure?

dave_59
dave_59
Forum Moderator
8746 posts
August 30, 2013 at 8:54 am

In reply to Hani John Poly:

Apparently, you slept through your Probabilities and Statistics class, and you don't gamble. Try flipping a coin 20 times and see how often it lands on the same side consecutively. A distribution is not like a hard constraint; it is only after a large number of iterations that your solution approaches the desired distribution.

If you have a hard constraint that a number from each of the three sets it picked in a cycle, then you cannot use the dist constraint. You can use the cyclic randc constraint to select between each set:

randc bit [2:0] delay_set;
rand  bit[3:0]  ack_delay;
 
constraint delay_set_limit { delay_set < 3 }
constraint ack_delay_constr { 
   delay_set==0 -> ack_delay ==1;
   delay_set==1 -> ack_delay inside {[2:5]};
   delay_set==2 -> ack_delay inside {[6:15]};
}

This gives you an exact even selection of each set in one cycle. If want multiple selection of sets in a cycle, or don't want the selections to be even increase the delay_set_limit:
randc bit [2:0] delay_set;
rand  bit[3:0]  ack_delay;
 
constraint delay_set_limit { delay_set < 8 }
constraint ack_delay_constr { 
   delay_set < 4 -> ack_delay==1;
   (delay_set==4 || delay_set==5) -> ack_delay  inside {[2:5]};
   delay_set inside {[6:7]} -> ack_delay  inside {[6:15]};
}

This gives you 4 selections of set 1, 2 selections of set 2:5, and 2 selections of set 6:15 in a cycle.

— Dave Rich, Verification Architect, Siemens EDA

Hani John Poly
Hani John Poly
Full Access
3 posts
September 03, 2013 at 4:12 am

In reply to dave_59:

Good guess! :)
Thanks Dave.

laureen.giac
laureen.giac
Forum Access
10 posts
April 02, 2018 at 5:40 am

In reply to dave_59:

Hi Dave,

Is 'dist inside' only supported in Questa? I can't find anything like this in the LRM.

Thanks

dave_59
dave_59
Forum Moderator
8746 posts
April 02, 2018 at 7:18 am

In reply to laureen.giac:

That was a typo. I'm surprised it took this long for someone to catch it. Thanks. I have removed 'dist' from the example.

— Dave Rich, Verification Architect, Siemens EDA

srshan_rocks
srshan_rocks
Full Access
2 posts
January 18, 2021 at 10:20 pm

Quote:

randc bit [2:0] delay_set;
rand  bit[3:0]  ack_delay;
 
constraint delay_set_limit { delay_set < 3 }
constraint ack_delay_constr { 
   delay_set==0 -> ack_delay ==1;
   delay_set==1 -> ack_delay inside {[2:5]};
   delay_set==2 -> ack_delay inside {[6:15]};
}

Hello Dave, don't you need solve delay_set before ack_delay to get an uniform distribution of
0 = 1/3, 1 = 1/3, 2 = 1/3

dave_59
dave_59
Forum Moderator
8746 posts
January 19, 2021 at 9:55 am

In reply to srshan_rocks:

No, because randc guarantees a uniform distribution of that random variable.

— Dave Rich, Verification Architect, Siemens EDA

Siemens Digital Industries Software

Siemens Digital Industries Software

##TodayMeetsTomorrow

Solutions

  • Cloud
  • Mendix
  • Siemens EDA
  • MindSphere
  • Siemens PLM
  • View all portfolio

Explore

  • Digital Journeys
  • Community
  • Blog
  • Online Store

Siemens

  • About Us
  • Careers
  • Events
  • News and Press
  • Newsletter
  • Customer Stories

Contact Us

USA:

phone-office +1 800 547 3000

See our Worldwide Directory

  • Contact Us
  • Support Center
  • Give us Feedback
©2021 Siemens Digital Industries Software. All Rights Reserved.
Terms of Use Privacy Cookie Policy