[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[oc] Re: question



Hi!

> Hello Andras
>
> Thank you for your input.
>
> I am wondering if the Rand function you mentioned is
> sythesizable or not?

Well, of course you can create a synthetizable (pseudo) random number
generator. The most common way to do that is the LFSR technique, which has
many implementations which I don't know much about. Probably there are
others too. What I've mentioned is not a function but a number (a bit-vector
in a somewhat VHDL style notation) containing the *result* of any such
function.

> If, suppose, the boundary number is not 9, it is
> changing with the inputs. What do you think the way to
> implement this?

You can generalize my previous algorithm for this scennario.

First of all, if the boundary is 2^n-1 than you can truncate the random
number and you're done.

If not, you have to add some kind of 'memory' to the process. In general you
can use the following:

Let's have the output number in the range of 0..k. Let's say that that
number can be presented in n bits, that is k < 2^n. With that said:

Output: output number with n bits, but in the range of 0..k
Random: an input (flat dist.) random number with n bits, and full range.
Temp: a number with n+1 bits.
Cnt: a counter with n bits (may be less, but that at least capable of
representing numbers between 0..2^n-2-k)

if (Random <= k) then
    Output <= Random
else
    ' Generate shifted output
    Temp <= Random-k-1+Cnt;
    ' Wrap-around at boundary
    if (Temp <= k) then
        Output <= Temp;
    else
        Output <= Temp-k-1;
    end if;
    ' Increment offset counter
    if (Cnt < 2^n-1-k) then
        Cnt <= Cnt + 1;
    else
        Cnt <= 0;
end if;

This will produce a flat distribution over the full output range. Also note,
that it's almost the same as John proposed. The main difference is the type
of 'memory' of the system.

Also, if you use LFSR to generate random numbers, you'd probably whish to
use a longer LFSR than n bits. In that case the first step would be to
truncate that number to n bits of course.

Andras Tantos



_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

--
To unsubscribe from cores mailing list please visit http://www.opencores.org/mailinglists.shtml