# Randomization seed

**URL:** <https://forum.uvvm.org/t/randomization-seed/106>\
**Category:** Utility Library\
**Tags:** uvvm, question\
**Created:** [October 1, 2020, 3:56am UTC](https://forum.uvvm.org/t/randomization-seed/106 "2020-10-01T03:56:28Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Riyazria](https://avatars.discourse-cdn.com/v4/letter/r/58956e/32.png) [@Riyazria](https://forum.uvvm.org/u/Riyazria)\
**Post date:** [October 1, 2020, 3:56am UTC](https://forum.uvvm.org/t/randomization-seed/106/1 "2020-10-01T03:56:28Z")

</div>

Hi Erick,

when i use a keyword called **random** it will give the random data. when i do multiple runs of simulation it is generating the same data every time. How can I get a different set of data at every time when I run the simulation?

In **UVM** we have an option of driving the seed from the makefile, do we have something similar here

Best Regards,

---

<div class="post-metadata">

**Author:** ![Erick](https://avatars.discourse-cdn.com/v4/letter/e/bbce88/32.png) [@Erick](https://forum.uvvm.org/u/Erick)\
**Post date:** [October 1, 2020, 6:04am UTC](https://forum.uvvm.org/t/randomization-seed/106/2 "2020-10-01T06:04:58Z")

</div>

Hi Riyaz,

I have moved this question to a new topic since it is not related to VVCs read back.  
In UVVM there is the randomize() function you can use to set the global seeds in your testbench. You can find more information on this in the util\_quick\_ref.pdf under uvvm\_util\doc.

Best Regards,  
Erick

---

<div class="post-metadata">

**Author:** ![Riyazria](https://avatars.discourse-cdn.com/v4/letter/r/58956e/32.png) [@Riyazria](https://forum.uvvm.org/u/Riyazria)\
**Post date:** [October 1, 2020, 6:32am UTC](https://forum.uvvm.org/t/randomization-seed/106/3 "2020-10-01T06:32:39Z")

</div>

Hi Erick,

thanks for moving it into a new thread

```
  a_in := random(a_in'length);
  b_in := random(b_in'length);
  opp := random(1,3);

```

I used the random function as above, but the type of inputs that are being generated was the same at each and every run. how can I get a different set of data for when I run it every time is my question?

Best Regards,  
Riyaz

---

<div class="post-metadata">

**Author:** ![Erick](https://avatars.discourse-cdn.com/v4/letter/e/bbce88/32.png) [@Erick](https://forum.uvvm.org/u/Erick)\
**Post date:** [October 1, 2020, 6:43am UTC](https://forum.uvvm.org/t/randomization-seed/106/4 "2020-10-01T06:43:06Z")

</div>

You can use the randomize function like I mentioned to change the global seeds on each run. You could use a generic for instance.

> randomize(GC\_SEED1, GC\_SEED2, “Setting global seeds”);  
> a\_in := random(a\_in’length);  
> b\_in := random(b\_in’length);  
> opp := random(1,3);

Best Regards,  
Erick

---

<div class="post-metadata">

**Author:** ![Riyazria](https://avatars.discourse-cdn.com/v4/letter/r/58956e/32.png) [@Riyazria](https://forum.uvvm.org/u/Riyazria)\
**Post date:** [October 1, 2020, 7:17am UTC](https://forum.uvvm.org/t/randomization-seed/106/5 "2020-10-01T07:17:33Z")

</div>

so this GC\_SEED1, GC\_SEED2 are generic constants, right?

so i need to update these in my test case or i should need to drive from somewhere

like makefile or do-file

Best Regards,  
Riyaz

---

<div class="post-metadata">

**Author:** ![Erick](https://avatars.discourse-cdn.com/v4/letter/e/bbce88/32.png) [@Erick](https://forum.uvvm.org/u/Erick)\
**Post date:** [October 1, 2020, 7:42am UTC](https://forum.uvvm.org/t/randomization-seed/106/6 "2020-10-01T07:42:31Z")

</div>

Yes, you can drive them from your do-file when you start the simulation, e.g.

> vsim -gGC\_SEED1=12 -gGC\_SEED2=14 …

Best Regards,  
Erick

---

<div class="post-metadata">

**Author:** ![Riyazria](https://avatars.discourse-cdn.com/v4/letter/r/58956e/32.png) [@Riyazria](https://forum.uvvm.org/u/Riyazria)\
**Post date:** [October 1, 2020, 7:44am UTC](https://forum.uvvm.org/t/randomization-seed/106/7 "2020-10-01T07:44:42Z")

</div>

yeah i did this but the data which is generating is the same throughout the simulation

there is no change in the data from the start to the end of the simulation

Best Regards,  
Riyaz

---

<div class="post-metadata">

**Author:** ![Erick](https://avatars.discourse-cdn.com/v4/letter/e/bbce88/32.png) [@Erick](https://forum.uvvm.org/u/Erick)\
**Post date:** [October 1, 2020, 7:59am UTC](https://forum.uvvm.org/t/randomization-seed/106/8 "2020-10-01T07:59:48Z")

</div>

But are you changing the seeds in the do-file every time you run it?  
I just made a quick test and I get different results:

RUN 1:

 ![image](https://europe1.discourse-cdn.com/flex017/uploads/uvvm/original/1X/5cd4b3766429febc7dfa33b94c01e88e2fae820a.png)  
RUN 2:  
 ![image](https://europe1.discourse-cdn.com/flex017/uploads/uvvm/original/1X/4be30d4f52e89864ca2b0c361b7272fb24d7f2cc.png)

Best Regards,  
Erick

---

<div class="post-metadata">

**Author:** ![Riyazria](https://avatars.discourse-cdn.com/v4/letter/r/58956e/32.png) [@Riyazria](https://forum.uvvm.org/u/Riyazria)\
**Post date:** [October 1, 2020, 8:03am UTC](https://forum.uvvm.org/t/randomization-seed/106/9 "2020-10-01T08:03:51Z")

</div>

i did it as follows

> constant GC\_SEED1 : integer := 10;  
> constant GC\_SEED2 : integer := 15;  
> begin  
> p\_main: process  
> begin  
> for i in 0 to 10 loop  
> randomize(GC\_SEED1, GC\_SEED2, “Setting Global Seeds”);  
> a\_in := random(a\_in’length);  
> b\_in := random(b\_in’length);  
> opp := random(1,3);  
> alu\_write(ALU\_INTF\_VVCT,1,a\_in,b\_in,std\_logic\_vector(to\_signed(opp,3)),‘1’,“Writing the data”, C\_SCOPE);  
> alu\_read(ALU\_INTF\_VVCT,1,“input data result”, C\_SCOPE);  
> v\_cmd\_idx := get\_last\_received\_cmd\_idx(ALU\_INTF\_VVCT, 1);  
> await\_completion(ALU\_INTF\_VVCT,1,150 ns); – this waits for all VVC cmds to finish  
> fetch\_result(ALU\_INTF\_VVCT,1, v\_cmd\_idx, v\_result, “Fetching result from read operation”);  
> wait for 10 ns;  
> end loop;

I did it like this for the fist run then changed the values again and ran but I didn’t get like you

can you tell me how to add my snapshot also like this I am unable to share it

Best Regards  
Riyaz,

---

<div class="post-metadata">

**Author:** ![Erick](https://avatars.discourse-cdn.com/v4/letter/e/bbce88/32.png) [@Erick](https://forum.uvvm.org/u/Erick)\
**Post date:** [October 1, 2020, 8:16am UTC](https://forum.uvvm.org/t/randomization-seed/106/10 "2020-10-01T08:16:07Z")

</div>

You are re-initializing the seeds on every iteration, therefore you get the same values.

The **randomize()** function should be placed outside the loop and run only once as the purpose is to set an initial value for the global seeds, after that the seeds will get updated with every call to the **random()** function.

You can just copy the snapshot directly into the reply box or upload an image.

Best Regards,  
Erick

---

<div class="post-metadata">

**Author:** ![Riyazria](https://avatars.discourse-cdn.com/v4/letter/r/58956e/32.png) [@Riyazria](https://forum.uvvm.org/u/Riyazria)\
**Post date:** [October 1, 2020, 11:59am UTC](https://forum.uvvm.org/t/randomization-seed/106/11 "2020-10-01T11:59:03Z")

</div>

Hi Erick,

I used this command to simulate my design

```
vsim -gui work.alu_demo_tb -voptargs="+acc" -quiet -suppress 12110 -do "wave_sanity.do" -do "log -r /*; run -all" -gGC_SEED2=14 -gGC_SEED1=12

```

I used this command in makefile it is working for me now

```
vsim -sv_seed random -gui -debugDB RX1_tb -assertdebug -do wave.do -do "log -r /*; run -all"

```

This command is used in **System Verilog** to run the simulation, where every time you call this command the seed value will also get generated randomly because of the keyword **random**

do we also have something like this which will do the random generation of seed values form the command line itself?

Best Regards,  
Riyaz

---

<div class="post-metadata">

**Author:** ![Erick](https://avatars.discourse-cdn.com/v4/letter/e/bbce88/32.png) [@Erick](https://forum.uvvm.org/u/Erick)\
**Post date:** [October 2, 2020, 6:46am UTC](https://forum.uvvm.org/t/randomization-seed/106/12 "2020-10-02T06:46:58Z")

</div>

I don’t think so, at least this is outside the scope of UVVM.

Best Regards,  
Erick
