# RandomPkg: How to set weight for range

Why OSVVM™? Forums OSVVM RandomPkg: How to set weight for range

Tagged:

Viewing 5 posts - 1 through 5 (of 5 total)
• Author
Posts
• #1387

Hi,

Is it possible to reduce next code:

` `

`     A <= RndA.DistValSlv(       ((0,5),        (1,1),(2,1),(3,1),(4,1),        (5,1),(6,1),(7,1),(8,1),(9,1),        (10,1),(11,1),(12,1),(13,1),(14,1),        (15,5)), A'length);`` `

I need to set Weight for range. For example in SV it looks like this:

``` a dist {0 := 5, [1:4] /= 5, [5:9] /=5, [10:14] /= 5, 15 := 5} ```

Thanks,

Nikolai

#1389

Hi Nicolai,

the argument type of DistValSlv is an array with a record of two integers.

I wonder wether the range notation can work here too.

It wold look somewhat like this:

`A <= RndA.DistValSlv(       ((0,5),        (1 to 14,1),        (15,5)), A'length);`

If this works not, maybe a function with a case statement can help.

In the function you then write sth. like this:

for position in 0 to 15 loop — 15 might come from some ‘lengh calculation
case position is
when 0 =>  ReturnVal(position,5);
when 1 to 14 =>ReturnVal(position,1);
when 15 =>ReturnVal(position,5);
end case;
end loop
return ReturnVal;

Unless there isn’t some better solution, this might at least be a useful  workaround for the moment.

(edit:) But actualy that won’t reduce the code much, unless you have a really big array of random constraints.

Have a nice simulation

Eilert

#1393

Hi Nikolai,

There is a simpler form of DistValSlv that returns values in the range of its argument, which is 0 to 15 if the argument is a literal or aggregate:

`     A <= RndA.DistSlv((5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5), A'length) ; `

If you prefer, you can also use named association:

`     A <= RndA.DistSlv((0=>5, 1=>1, 2=>1, 3=>1, 4=>1, 5=>1, 6=>1,                         7=>1, 8=>1, 9=>1, 10=>1, 11=>1, 12=>1,                         13=>1, 14=>1, 15=>5), A'length) ; `

With named association, you can also do the following:

`     A <= RndA.DistSlv((0=>5, 1 to 14 =>1, 15=>5), A'length) ; `

You can also do this with a coverage model:

`     shared variable ACov : CovPType ;      . . .     process     begin       ACov.AddBins(5, GenBin(0)) ; ``       ACov.AddBins(1, GenBin(1,14)) ;``       ACov.AddBins(5, GenBin(15)) ; `

`       . . .       A <= ACov.RandCovPoint ;        ACov.ICoverLast ;`

Jim

#1396

Hi Eilert, Jim,

Thank you for the answers. They are very useful for me.

Nikolai

#1398

Hi Jim,

I hoped that there’s some solution using the range notation like you showed:

With named association, you can also do the following:

`     A <= RndA.DistSlv((0=>5, 1 to 14 =>1, 15=>5), A'length) ;`

``` ```

I just didn’t expect it to be so straight simple, since the defined type is self defined.
You mentioned integer_vectors somewhere else. Are these defined internally in a similar way as DistValSlv is? Does this kind of assignment work with integer_vectors too?

Kind regards
Eilert

Viewing 5 posts - 1 through 5 (of 5 total)
• You must be logged in to reply to this topic.