How to manage the seed of randomization?

Dear all,
Maybe it is not a question for OVM but systemverilog.
I remember,in Vera code you set the seed of the randomization.
This ability can help us:
1.geneate any seed you want and display it.
when you display it ,you can know which seed runing for specify case.
2.set your seed.
you can use an random value to set to your seed to make the same test case can run under diffirent seed.
also,you can re-run this test in a specific seed which make test fail.

Can systemverilog do that under his syntax? or OVM can help systemverilog to do this random seed management?

Thank you!

Hi,

SystemVerilog includes functions for controlling and reporting the randomization settings (see section 17.13 of the draft 3 p1800 standard that is available from the IEEE).

srandomallows you to specify the seed that is used by an object or process.

get_randstate returns a string containing the current state of the random number generator

set_randstate allows you to set (restore) the random number generator state using a string (from an earlier call to get_randstate).

The ovm_object class has a reseed function that generates a random seed from an object’s type name and hierarchical path which it then passes to srandom. This mechanism can be disabled by setting the static member ovm_object::use_ovm_seeding = 0 (the default is 1).

The reseed function is called for ovm_sequence_item to ensure sequences get random seeds. You can also call it for any other object derived from ovm_object, e.g. a custom stimulus generator.

Hope that answers your question.

Regards,
Dave

With Cadence simulator, global seed management is done on command line:

irun -svseed random …

or
irun -svseed …

Hi Dave and Jigar,
Thanks for your information!
My concern is just as Jigar mentioned.
Global seed of the verification enviroment.
Could systemverilog syntax can support to set the global seed?
or It is just set by simulator command line?
I don’t think it’s a good solution to specify in the simulator command line.
The problem is,if you set it in command line,it’s not easy to log it,it’s not easy to mantain it and use a random value to set it.
Thank you!

Two reasons why the global seed needs to be set by the command line:

  1. The seed needs to be set before any statement executes because of static variable initializations.
  2. Even if you could set the global seed from within the langauge, you would most likely want to set the seed from the command line so that you could run the same simulation again with different global seeds.

Hi Dave Rich,
Thanks for your help!
Then my question is:
How can we use sv syntax to set global seed as well as command line does?
Do simulator can work exact the same if he set the same global seed in code as in command line?
Thank you!

Hello ahan,

I’m not sure what your objective is for setting the seed inside the SV code and also setting from the command line?

In IUS (and I’m sure Questa as well…) you have the option to set the seed from the command line:

-svseed int_number

OR

-svseed random

If you don’t set a seed, it will default to 1

In all cases, the seed is printed into the log file so you can re-run a simulation and specify the seed you want.

The OVM library has built-in random seed stability. All objects derived from ovm_object have this implemented. Please take a look at the OVM Reference (page 12) to see more information about using the OVM built-in seeding. You have the option to do something else as well but I suggest you use the capability that was built into the library.

Kathleen

In reply to dave_59:

Dave,

How do we set the cmd line seed? and how do we give a global seed in SV code?

In reply to Ammu4392:

Please look in the user manual for your simulator. This forum is not for tool specific help.

In reply to ahan:

Just for completion.
If you are interested on reading the seed set on the command line, the UVM provides a class called uvm_cmdline_processor. You can use this uvm_cmdline_processor class for example in the build_phase. The uvm_cmdline_processor class provides nice functions to extract arguments from the command line.

Some usage examples


 uvm_cmdline_processor   clp = uvm_cmdline_processor::get_inst();
string                  arg_values[$];
string                  cmdline[string];
void'(clp.get_arg_values("+uvm_set_config_int=", arg_values));
//seed
void'(clp.get_arg_values("-seed=", arg_values));
//you can check if an argument exists
exist_arg = clp.get_arg_value("+PVE_HEARTBEAT", cmdstring);
...
//you can parse for specific argument stringlists
function void parseCmdLine(stringlist sl);
        string cmdstring;
        foreach(sl[i]) begin
            if(clp.get_arg_value(sl[i], cmdstring) > 0) begin
                cmdline[sl[i]] = cmdstring;
            end
        end
    endfunction