Help on using DistValInt
Why OSVVM™? › Forums › OSVVM › Help on using DistValInt
- This topic has 2 replies, 2 voices, and was last updated 12 years, 11 months ago by
Alvin Manlapat.
-
AuthorPosts
-
November 4, 2012 at 16:11 #416
Alvin Manlapat
Member*Hi,
I was trying to use DistValInt in my code but I keep getting one output value.
I’ve decraled the variable inside the PROCESS as:
variable rndx : RandomPType;
variable tmp_val : integer;
then I’ve used it as:
rndx.InitSeed(SEED);
tmp_val := rndx.DistValInt(((1,1),(2,5),(3,3),(4,1)));
I changed the value of SEED a couple of times (e.g. 1234, 555, 5567) but I was always getting 1 as result for tmp_val. Did I miss something in my equations?
Thank you in advance for help and suggestions.
November 5, 2012 at 10:34 #417
Jim LewisMemberHi Alvin,
You need to show more code. I can’t tell how many times you call DistValInt. What I would expect to see is:process variable rndx : RandomPType; variable tmp_val : integer; begin rndx.InitSeed(SEED); -- do one time. loop 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.
Have you looked at RandomPkg_user_guide.pdf?
Best,
JimNovember 5, 2012 at 12:03 #419Alvin Manlapat
MemberHi Jim,
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;report "counts: " & to_string(counts(0)) & ","
& to_string(counts(1)) & ","
& to_string(counts(2)) & ","
& to_string(counts(3));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.
Thanks a lot for your help,
Alvin
-
AuthorPosts
- You must be logged in to reply to this topic.