Task #5676
closed[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 }; }