## Task #5676

### [generator] Random generation - weighting / biasing distribution

100%

**Description**

Subj. must be implemented.

Discussion about the randomisation/seeding/biasing/buckets point (Randomisation and seeding / Biasing – not just :min, :max , but buckets):

we were thinking about something available in languages with support for constrained-random activity, like Specman 'e' and SystemVerilog.

For instance this is a SystemVerilog example taken from http://www.asic-world.com/systemverilog/random_constraint7.html :

constraint src { src_port dist { 0 := 1, 1 := 1, 2 := 5, 4 := 1 }; } constraint des { des_port dist { [0 : 5 ] :/ 5, [6 : 100 ] := 1, [101 : 200 ] := 1, [201 : 255 ] := 1 }; }

Basically the "dist" construct allows a "distribution" of probability to be specified.For instance the value of "src_port" can have values 0,1,2,4, where values 0,1,4 all have the same weight whereas value 2 has five times the weight of the others.

As the total sum of all the weights is 8, values 0,1,4 will be extracted 1/8 of the time each (i.e. 12.5%), whereas value 2 will have a probability of 5/8 (i.e. 62.5%).

The second example for "dst_port" is a bit more complex (you can find an explanation of the operators here: http://www.testbench.in/CR_15_CONSTRAINT_EXPRESSION.html ).

Basically all the values comprised for instance in the second range [6:100] will all have a weight of 1 each; whereas those in the first range will share the same weight of 5 (so the six numbers will have a weight of 5/6 each).

Each of these ranges can be considered a "bucket" (but we usually refer to this as "distributions" at the time of generation and "bucketing" at the time of collecting coverage).

In addition of getting generating values match the desired distribution across multiple generated tests, it is desirable to be able to generate exactly the same test again if the generator is invoked with the same randomization seed (typically from the command line).

Please note that the probability distribution doesn't necessarily have to only work with numbers, for instance something like this could be envisaged for load instructions:

constraint c_LD_instr { LD_instr dist { LDR := 1, LDRB := 1, LDRH := 5, LDUR := 1 }; }

### History

#### Updated by Andrei Tatarnikov about 5 years ago

**Status**changed from*New*to*Open***% Done**changed from*0*to*20*

The test template construct will look like this:

```
my_dist = dist range(:value => 10, :bias => 3),
range(:value => 10..30, :bias => 7),
range(:value => [10, 20, 30], :bias => 2)
add t0, t1, t2 do situation('random', :size => 32,
:dist => [range(:value=> 1, :bias => 100), # Single
range(:value=> 1..3, :bias => 2), # Interval
range(:value=> [1, 10, 3], :bias => 33), # Collection
range(:value=> my_dist, :bias => 7)] # Distribution
) end
```

#### Updated by Alexander Kamkin about 5 years ago

Support for randomization constructs has been implemented in Fortress (see the ru.ispras.fortress.randomizer package).

#### Updated by Andrei Tatarnikov about 5 years ago

**% Done**changed from*60*to*80*

Implementation is ready r3250. But a good example is needed.

#### Updated by Andrei Tatarnikov about 5 years ago

**Status**changed from*Open*to*Resolved***% Done**changed from*80*to*100*

#### Updated by Andrei Tatarnikov about 5 years ago

**Status**changed from*Resolved*to*Closed***Published in build**set to*150305*