In reply to bsivakumar:
class array;
rand int is_cons;
int rand_i[18];
int fixed_arr1[14] = '{1,1,2,2,3,3,4,5,6,7,8,8,9,10};
rand int part_arr[4];
int fixed_arr2[4][] = '{'{1,2,3},'{4,5},'{6,7},'{9,10}};
constraint c1 { foreach(part_arr[i]) part_arr[i] inside {fixed_arr2[i]}; }
function void post_randomize();
rand_i = {fixed_arr1,part_arr};
if(is_cons)rand_i.sort();
else rand_i.shuffle();
endfunction
endclass
module tb;
array a;
initial begin
a=new();
repeat(10)begin
a.randomize() with {is_cons==1;};
$display("%0p",a.rand_i);
end
$display("\n\n");
repeat(10)begin
a.randomize() with {is_cons==0;};
$display("%0p",a.rand_i);
end
end
endmodule
//OUTPUT:
'{1, 1, 2, 2, 2, 3, 3, 4, 4, 5, 6, 7, 7, 8, 8, 9, 10, 10}
'{1, 1, 2, 2, 3, 3, 3, 4, 4, 5, 6, 7, 7, 8, 8, 9, 9, 10}
'{1, 1, 2, 2, 3, 3, 3, 4, 4, 5, 6, 7, 7, 8, 8, 9, 10, 10}
'{1, 1, 2, 2, 3, 3, 3, 4, 5, 5, 6, 6, 7, 8, 8, 9, 9, 10}
'{1, 1, 2, 2, 2, 3, 3, 4, 5, 5, 6, 6, 7, 8, 8, 9, 10, 10}
'{1, 1, 2, 2, 2, 3, 3, 4, 5, 5, 6, 6, 7, 8, 8, 9, 9, 10}
'{1, 1, 1, 2, 2, 3, 3, 4, 5, 5, 6, 7, 7, 8, 8, 9, 10, 10}
'{1, 1, 2, 2, 3, 3, 3, 4, 5, 5, 6, 7, 7, 8, 8, 9, 9, 10}
'{1, 1, 2, 2, 2, 3, 3, 4, 5, 5, 6, 7, 7, 8, 8, 9, 10, 10}
'{1, 1, 1, 2, 2, 3, 3, 4, 5, 5, 6, 6, 7, 8, 8, 9, 9, 10}
'{1, 2, 3, 8, 9, 6, 10, 5, 5, 1, 9, 2, 7, 3, 7, 4, 8, 1}
'{6, 2, 4, 6, 3, 2, 7, 8, 8, 10, 1, 3, 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