Random distribution in VHDL

J

Jonathan Bromley

Guest
hi comp.lang.vhdl,

A few moments ago I posted a response about random time
delays, and it got me thinking: in VHDL we have
ieee.math_real.uniform() to give flat (uniform) random
distributions, but Verilog also has a bunch of other
distributions available: $dist_gaussian, $dist_poisson
and a few more. Gaussian and Poisson are both *very*
useful for testbench applications - for example, the
random timing jitter I posted about should probably
have a gaussian distribution; when modelling the
number of wait states introduced on bus read cycles,
Poisson distribution usually works well.

Has anyone done these for VHDL and made them public?
Or are they in one of the standard libraries, and
I just failed to spot them all these years? There
are C reference algorithms in the Verilog LRM, so it
should not be too difficult to reproduce them in VHDL.

thanks
--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services

Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
jonathan.bromley@MYCOMPANY.com
http://www.MYCOMPANY.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
 
Jonathan Bromley <jonathan.bromley@MYCOMPANY.com> writes:

Has anyone done these for VHDL and made them public?
Yes. For quite a while now this has been made available on Janick's
Verification Guild.

http://verificationguild.com/dload/utils/vhdl/random1.vhd

Not a standard package, though.

Regards
Marcus

--
note that "property" can also be used as syntaxtic sugar to reference
a property, breaking the clean design of verilog; [...]

(seen on http://www.veripool.com/verilog-mode_news.html)
 
On Tue, 14 Jul 2009 13:14:02 +0200, Marcus Harnisch wrote:

For quite a while now this has been made available on Janick's
Verification Guild.
http://verificationguild.com/dload/utils/vhdl/random1.vhd
Thanks Marcus. It looks good. I particularly like the
idea of packaging the whole randomization state as a
record, though it would be even nicer as a protected type.

Not a standard package, though.
No worries about that.
--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services

Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
jonathan.bromley@MYCOMPANY.com
http://www.MYCOMPANY.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
 
Jon and all,
This looks like a good thing to add to our randomization
packages (open source) that are available
at: http://www.synthworks.com/downloads/index.htm

Currently RandomPkg uses uniform to generate numbers between
0.0 and 1.0. I setup a mode so I could switch in any
randomization function that also generates numbers between
0.0 and 1.0. So adding Gaussian and Poisson should be
pretty easy.

The question I have is, is it valid to generate a Gaussian
random number with a mean of 0.5 and a standard deviation
of 1/6 (.16667) and then scale it separately to a range.
I am thinking the standard deviation should be 1/6 so that
at 3*standard deviation when the value has mostly
died out. Is it valid to clip it to 0.0 and 1.0?

Are there others that I should add other than Gaussian
and Poisson?

Cheers,
Jim
SynthWorks VHDL Training
www.SynthWorks.com
 
"JimLewis" <Jim@SynthWorks.com> wrote in message
news:d939a85a-2b0c-4b44-9592-57ca6037308a@c1g2000yqi.googlegroups.com...
Jon and all,
This looks like a good thing to add to our randomization
packages (open source) that are available
at: http://www.synthworks.com/downloads/index.htm
I agree.

I am thinking the standard deviation should be 1/6 so that
at 3*standard deviation when the value has mostly
died out. Is it valid to clip it to 0.0 and 1.0?
Clipping will likely make it not right for certain applications that would
be expecting a correctly generated random number sequence with the chosen
distribution...just my 2 cents

KJ
 
On Tue, 14 Jul 2009 23:19:55 -0700 (PDT), JimLewis wrote:

Is it valid to clip it to 0.0 and 1.0?
No, I don't think so. Even though 6-sigma
is very unlikely, it seems like a recipe for
trouble to offer a Gaussian distribution
that isn't. Someone wise once pointed out to
me that the greatest mistake any programmer can
make is to confuse "unlikely" and "impossible".

Are there others that I should add other than Gaussian
and Poisson?
I'd go back to my original point: why not implement
the same distribution algorithms that are published
in the IEEE Verilog standard? That would be a help
to verification engineers who use both languages.
Of course the API must be somewhat different because
VHDL functions can't have side-effects [*], but the
functionality can be the same.

[*] unless the whole thing is done with protected
types, of course, in which case the seed can
be a private property of the object.
--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services

Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
jonathan.bromley@MYCOMPANY.com
http://www.MYCOMPANY.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
 
Is it valid to clip it to 0.0 and 1.0?

No, I don't think so.  Even though 6-sigma
is very unlikely, it seems like a recipe for
trouble to offer a Gaussian distribution
that isn't.  Someone wise once pointed out to
me that the greatest mistake any programmer can
make is to confuse "unlikely" and "impossible".
Good point.

How about re-randomizing values that exceed the bounds?
Also make the re-randomization point settable by making
the standard deviation or number of sigmas to keep
settable?

Are there others that I should add other than Gaussian
and Poisson?

I'd go back to my original point: why not implement
the same distribution algorithms that are published
in the IEEE Verilog standard?  
Gag. I have to look in the Verilog manual. Yuck.
Ok I found:
dist_functions :: $dist_uniform ( seed , start , end )
| $dist_normal ( seed , mean , standard_deviation )
| $dist_exponential ( seed , mean )
| $dist_poisson ( seed , mean )
| $dist_chi_square ( seed , degree_of_freedom )
| $dist_t ( seed , degree_of_freedom )
| $dist_erlang ( seed , k_stage , mean )

Are all of these used or did they do them just because
they could?

unless the whole thing is done with protected
    types, of course, in which case the seed can
    be a private property of the object.
The only way to do it.

This has been a good exercise. I think
I have some reorganization in the packages to do.

Cheers,
Jim
 
"JimLewis" <Jim@SynthWorks.com> wrote in message
news:a43c6258-aa29-4042-bdd5-ba1e4df8863f@y19g2000yqy.googlegroups.com...
How about re-randomizing values that exceed the bounds?
Also make the re-randomization point settable by making
the standard deviation or number of sigmas to keep
settable?
That's one valid concept; as a systems guy I could then decide on the trade
for tails accuracy versus speed. For instance, IIRC a common quick and dirty
means of generating a Gaussian is to use 12 draws of a 0..1 uniform
distribution. The mean is 6, and the sigma is 1.0 (the sigma of the uniform
distribution is 1/sqrt(12), so adding 12 together gives a sigma of 1.0).
That does mean that draws outside +- 6 sigma don't occur, but those are
extremely rare (my dog-eared reference for that is at work). I wouldn't
necessarily trust that distribution beyond 4 sigma, but that covers
something like 99.999% or more of the distribution. Your uniform random
number generator may be flaky at that level though as well. I know Matlab
has gone through several generations of rand() functions to meet user
demands for purity. When you're doing a multi-million point Monte Carlo
(e.g., simulating ultra-rare particle physics events in your QCD model) or
other high end math that relies on a good random number generator you start
to care about those things. Most of the time you don't give a fig.

The canonical means of generating a Gaussian random draw is to use the
inverse error function (inverse of the integral of the Gaussian) to map from
the uniform distribution (again, vanilla rand() is suspect) to the desired
one. Many math libraries (e.g., libm on most Unixes, I think it's there in
Windows as well) support that special function. It may require distributing
a sharable object library with your VHDL/Verilog and using whatever hooks
there might be for Modelsim and other simulators to access user-written C
code, or pestering Mentor et al.

Marty
 
That's one valid concept; as a systems guy I could then decide on the trade
for tails accuracy versus speed. For instance, IIRC a common quick and dirty
means of generating a Gaussian is to use 12 draws of a 0..1 uniform
distribution. The mean is 6, and the sigma is 1.0 (the sigma of the uniform
distribution is 1/sqrt(12), so adding 12 together gives a sigma of 1.0).
That does mean that draws outside +- 6 sigma don't occur, but those are
extremely rare (my dog-eared reference for that is at work). I wouldn't

There is also the Box-Muller transform.

http://en.wikipedia.org/wiki/Box-Muller_method

Barry
 

Welcome to EDABoard.com

Sponsor

Back
Top