# Reply To: Random seed problem

Why OSVVM™? Forums OSVVM Random seed problem Reply To: Random seed problem

#1426
Jim Lewis
Member

Hi Torsten

This is an interaction between ieee.math_real.uniform and the seeds.  Throw out your first random number and the rest look good.

Exciting issue.   I explored this issue with the following similar procedure.

```   procedure RandProTest is      variable RV    : RandomPType;      variable vSeed : RandomSeedType;      variable vTime : time;      variable vInt  : integer;      variable vReal : real;  begin--      RV.InitSeed(RV'instance_name & to_string(now));--      RV.InitSeed(to_string(now));      RV.InitSeed(now / 1 ns);      print(RV'instance_name & to_string(now));      print("Seed: " & to_string(RV.GetSeed)) ;       vSeed := RV.GetSeed ;       for i in 1 to 5 loop         -- print("Seed: " & to_string(vSeed)) ;         ieee.math_real.uniform(vSeed(vSeed'left), vSeed(vSeed'right), vReal) ;         print("vReal * 100: " & to_string(integer(round(vReal*100.0)))) ;      end loop ;       for i in 1 to 5 loop          -- print("Seed: " & to_string(RV.GetSeed)) ;         vInt := RV.RandInt(0, 100);        print("vInt: " & to_string(vInt));      end loop ;  end procedure RandProTest; ```

Note if you run this that the first number out for most calls to the procedure are identical.   However, after that they are different.

Really quick it started to look an interaction between ieee.math_real.uniform and the seeds, so I called uniform directly in the procedure.  I explored seeds some.   The seeds generated using strings while different were fairly close numerically.   To get some greater differences in the seeds, I tried (now / 1 ns).   While these seeds were reasonably different,  the first number randomized was mostly the same.

The good news is that the numbers generated after the first number look good.

Long Term Solution:

A better seed hashing function may help.   I have thought about doing this in the past, however, it will change everyone’s tests.   Hence, I hesitate.  I think if it gets changed, it can get changed one time.   In addition, based on this test, InitSeed should probably call uniform one time and that would address any deficiencies in the hashing.

Thoughts?