( ESNUG 390 Item 3 ) --------------------------------------------- [03/20/02]

From: Alexandre Gnusin <alexandre.gnusin@tundra.com>
Subject: Alexandre's Easier To Use Vera Randomization/Semi-Random Functions

Hi John,

In my opinion, Vera is too object-oriented.  This Vera obession on object
orientation means that some straightforward functions, built-in into
classes, are not available for straightforward procedural programming.

For example, there are no simple randomization functions that are easily
useable for random and semi-random tests.  We had to overcome this problem
creating our own random functions:

  class RL {
    rand integer num;
    integer low, high, flag;
    constraint main {
      num <= high;
      num >= low;
      num dist {low:low+(high-low)/3 :/80,
                low+(high-low)/3:high-(high-low)/3:/15,
                high-(high-low)/3:high :/5};
    }
  }

  class RN {
    rand integer num;
    integer low, high, flag;
    constraint main {
      num <= high;
      num >= low;
    }
  }

  class RH {
    rand integer num;
    integer low, high, flag;
    constraint main {
      num <= high;
      num >= low;
      num dist {low:low+(high-low)/3 :/5,
                low+(high-low)/3:high-(high-low)/3:/15,
                high-(high-low)/3:high :/80};
    }
  }

  function integer rl (integer low, integer high) {
    RL p= new;
    p.low = low;
    p.high = high;
    if(!p.randomize()) error("Randomization error") ;
    rl = p.num;
  } 

  function integer rn (integer low, integer high) {
    RN p= new;
    p.low = low;
    p.high = high;
    if(!p.randomize()) error("Randomization error") ;
    rn = p.num;
  } 

  function integer rh (integer low, integer high) {
    RH p= new;
    p.low = low;
    p.high = high;
    if(!p.randomize()) error("Randomization error") ;
    rh = p.num;
  } 

Here is an example of random functions usage:

 for (i=1; i<20;i=i+1) Send_NWRITE (rl(0,2), 64, 0, rn(0,2), 8*rl(1,31), 0);

Each of these functions, rl, rn, and rh returns a random integer between
our specified low and high limits.  The difference between them is that
rl will return more likely a "small" number, rn - any number and rh - a
"high" number.

    - Alexander Gnusin
      Tundra Semiconductors                      Ottawa, Ontario, Canada


 Sign up for the DeepChip newsletter.
Email
 Read what EDA tool users really think.


Feedback About Wiretaps ESNUGs SIGN UP! Downloads Trip Reports Advertise

"Relax. This is a discussion. Anything said here is just one engineer's opinion. Email in your dissenting letter and it'll be published, too."
This Web Site Is Modified Every 2-3 Days
Copyright 1991-2024 John Cooley.  All Rights Reserved.
| Contact John Cooley | Webmaster | Legal | Feedback Form |

   !!!     "It's not a BUG,
  /o o\  /  it's a FEATURE!"
 (  >  )
  \ - / 
  _] [_     (jcooley 1991)