You need to show more code. I can’t tell how many times you call DistValInt. What I would expect to see is:
variable rndx : RandomPType;
variable tmp_val : integer;
rndx.InitSeed(SEED); -- do one time.
tmp_val := rndx.DistValInt(((1,1),(2,5),(3,3),(4,1)));
-- do something
end loop ;
One key point is that the seed is a state variable and is only set one time at the beginning. A given seed will always produce the same sequence – this is important for test stability. WRT trying different seeds and always getting a 1 first – this is possible since you have a 25% chance of it happening. Although several generate the same initial value, it is likely that they will generate a different sequence.
I’ve tried something similar to your example code and now it produced the results that I was expecting.
counts := (0,0,0,0); for i in 0 to 100 loop tmp_val := rndx.DistValInt(((1,1),(2,5),(3,3),(4,1))); case (tmp_val) is when 1 => counts(0) := counts(0)+1; when 2 => counts(1) := counts(1)+1; when 3 => counts(2) := counts(2)+1; when 4 => counts(3) := counts(3)+1; when others => counts := counts; end case; end loop;
I got "Note: counts: 8,54,27,12" in my simulation run.
Yesterday I did not execute the rndx.DistValInt() multiple times and I only tested a few SEED values to initialize my random variable and I think that was the reason why I did not observe the generation of tmp_val properly.