set a random seed

125 views
Skip to first unread message

David Stanford

unread,
Sep 12, 2017, 9:17:39 AM9/12/17
to SVUnit User Group
In case anyone else is trying to figure this out on their own, I'll share my work. 

Today I was trying how to set the random seed of my SVUnit runs to be different on a run to run basis. The easiest way I could figure it out that doesn't require another scripting language or file rights is to pass in a parameter 'SEED' on the command line, and set it's value to the desired seed. In this case, I used $(date +%s) to set the seed to the seconds since the linux epoch, though using $((RANDOM)) or /dev/urandom might be better depending on your use case. 


command line: 
 runSVUnit -s modelsim -d SEED=$(date +%s)


in my verilog code: 

integer r;
 r = $urandom(`SEED);

Tudor Timi

unread,
Sep 13, 2017, 1:25:28 PM9/13/17
to SVUnit User Group
There's the '-r' option you can use to pass run time arguments. Something like:

    runSVUnit -s modelsim -r '-seed <whatever>'

I'm not sure what the command line parameter is for QuestaSim, but I would assume it's '-seed'.

Note: using randomization in unit tests is typically considered a unit testing sin, because your tests aren't reproducible. At the same time, having a fixed seed can help, because you can say that you can use the seed to reproduce a certain test run. On the other hand, it opens up the "random stability" can of worms, where small changes in the code can lead to the major changes in the behavior of a test run for a certain seed.
Reply all
Reply to author
Forward
0 new messages