How to manually set randomization Seed

Source: Internet
Author: User
Tags random seed

constrained random excitation is the most important feature in the SV verification language. Here, a problem that is often overlooked by verification engineers is the Randomization seed ).
we know that $ urandom in the $ random or SV in the Tilde generates only pseudo-random numbers. That is to say, if the seed is not changed, the random numbers produced by each simulation are the same.
the constrained randomization method of SV is also a bit the same as above. In SV, each object maintains its own internal RNG and is exclusively used in the randomize () method, which makes the Randomization of the object independent. When an object is generated, the next value of RNG of the thread that created it is used to set it as the Random Seed of RNG. In this case, the default seed value of the new function () of the object is 1. If the value of seed is not changed, the same incentive data will still be generated during each run simulation.
therefore, we need to manually set the Randomization seed in the new () function so that random incentives can be obtained for each run simulation.
the method for manually setting the random seed of the object RNG is to use srandom () to transmit the seed to the random variable seed, which ensures that before any class member variable is randomize, set a new randomization seed for the RNG of the object. Example:

1Class packet;
2Rand bit [15:0] Header;
3...
4FunctionNew (IntSeed );
5This. srandom (SEED );
6...
7Endfunction
8Endclass

In this way, we will set a new randomization seed for RNG from the External:

1Packet P = new (200);//Create P with seed 200.
2P. srandom (300);//Re-seed P with seed 300.

ActualCodeWe can define the seed macro as a different value, or use the system time as seed. First, we define the variable seed:

1 ModuleTest;
2IntegerSeed;
3Initial Begin
4If(! $ Value $ plusargs ("Seed = % d", Seed ))
5Seed =10;
6...
7End
8 Endmodule

Run the simulation command to take the system time as seed:

VCs-r test. V + plusargs_save + seed = 'date + % N

Another method that is frequently used is to add + ntb_random_seed_automatic to the simulation command. The variable seed does not need to appear in the Code and only needs to have random constraints:

 1 'Timescale 1ns/1ns
2 Program test;
3 Integer I;
4 Class RC;
5 Rand Int A;
6 Constraint con {A> 0 ;}
7 Endclass
8
9 Initial Begin
10 Rc ua = new ();
11 For (I = 0 ; I < 10 ; I ++) Begin
12 UA. randomize ();
13 $ Display ( " % D " , UA. );
14 End
15 $ Display ( " % D " , $ Urandom );
16 End
17 Endprogram

The simulation command is as follows:

 
VCs-sopengl-r test. sv + plusarg_save + ntb_random_seed_automatic

Finally, let's talk about it for reference only.

I personally think it is best to use a file to record the seed you used each time during randomization, the reason is that you can compare the current seed with all the previously recorded seed in the file before each run simulation. If it is different, you can use it to make the randomness more random; in addition, the saved seed can reproduce the simulation and facilitate debugging.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.