On 25 Aug, 20:29, indu <sangeethasn...@gmail.com> wrote:
> Thanks. I have initialised it but the seed does not seem to be
> changing.
>
> Im pasting a snippet of my code.
>
> procedure random_vector(
> * variable seed1 :inout integer;
> * variable seed2 :inout integer;
> * variable vmax * : in integer;
> * variable result : out integer ) is
>
> * *variable x : real;
> * *begin
> * * * * UNIFORM(seed1,seed2,x);
> * * * * i := integer(x) mod vmax;
> * * * * result := i;
> * end procedure random_vector;
> begin
> xx: process is
> ...
> ...
> variable seed1, seed2 *: integer := 1
> random_vector(seed1 => seed1, seed2 => seed2, vmax, x=>x);
>
> ...
> end process
>
> When I run this behavorial code, I see that the value of seed does not
> change between calls. Am I doing something wrong here?
>
> Thanks,
>
The seed values have to be possitive, but this should only throw an
error rather than not work at all, but you have a problem with the x
output from the UNIFORM function.
> UNIFORM(seed1,seed2,x);
> i := integer(x) mod vmax;
> result := i;
X is a real value that will be a value between 0 and 1. casting it to
and integer will then just result in 0 or 1, and overall your "result"
value will end up just being 0 or 1, regardless of VMAX. You need to
take the returned x value and use that the scale the return value to
something more meaningful. It is best to work with real types until
the very end.
In the words of blue peter: here's one I prepared earlier:
procedure rand_int( variable seed1, seed2 : inout positive;
min, max : in integer; --
boundaries for the random result (inclusive)
result : out integer) is
variable rand : real;
begin
uniform(seed1, seed2, rand);
result := integer(
real(min) --set the base
+ (rand * (real(max)-real(min)) ) -- add in the random
offset from the base, over a given range.
);
end procedure;