In reply to salmanepos:
array[0].type == TYPE_A;
array[1].type == TYPE_B;
others TYPEA or B;
How do i randomize the balanced or unbalanced brackets across the whole array? Thanks
This is pretty easy to randomize:
class instruction_stream;
rand instruction instrs[];
constraint num_of_instrs {
instrs.size() <= 10;
}
constraint first_two_instrs {
instrs[0].type == TYPE_A;
instrs[1].type == TYPE_B;
}
endclass
Since randomization can’t create objects, you’ll need to make sure you have enough already constructed objects in the array. This way, a call to randomize() can just throw away the objects it doesn’t need:
function void pre_randomize();
instrs = new[10]; // magic number '10' could a constant defined somwhere else
foreach (instrs*)
instrs[i] = new();
endfunction
I prefer doing the pre-allocation in [i]pre_randomize()*, because this way it always gets done before any call to randomize(). This way, it’s not problem if you create a single stream and randomize it multiple times.
For your instruction interdependencies (the “brackets”), you’ll need to be a bit more specific, since it’s not really clear what you intend to constrain.