Intentions behind Random function overloading

Why OSVVM™? Forums OSVVM Intentions behind Random function overloading

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #1074

    Hi,

    while reading the Random Package sources and documentation I wondered why there are overloaded sets of random functions separately for each type (int, signed, unsigned and slv)

    What’s the idea behind this?

    Wouldn’t overloading allow for a single Random function name covering all kind of types?

    e.g if I have some adder code

       y<=a+b;

    as long as the provided types are valid for the “+” function it just depends on the type declaration of a, b and y what the code actually does.

    But then, a testbench using the random package wold need to be reworked if the type declarations change for some reason.

    e.g.
    –Signed Data feed:

       a <= A.RandSigned(...);

       b<= B.RandSigned(...);

    needs to be changed to

       a <= A.RandUnsigned(...);

       b<= B.RandUnsigned(...);

     while a (fictional) generic overloaded function would provide the correct type according to the assignment destination type:

    e.g.

      a <= A.Random(...);

      b<= B.Random(...);

    I mean, that’s what overloading and strict typing is good for, isn’t it?

    Are there cases where this wouldn’t work as described, or any other reasons that I did not see?

    Kind regards

      Eilert

    #1075
    Jim Lewis
    Member

    The intent behind functions is to be able to randomize values and use them in the a larger expression.  Hence, I had concerns, perhaps unfounded, over ambiguous expressions.   I decided that I would rather start with something that always works and add a simplified overloaded version later.

    #1077

    Hi Jim,

    sorrry if my question was not stated properly.

    There’s no doubt about using functions in general.

    I just wondered wether there’s some reason to have separate function names for each return type rather one function name that is valid for all return types.

    But if you say that there’s no technical reason for it and a generic Random function can/will be added in some future release that’s OK.

    I just wanted to understand the intentions behind the way you did it.

    Kind regards

      Eilert

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.