While randomizing 3 values, if one value repeat for 2 times, then other two values should repeat for one time

The variable rand_i is having 10 values(1,2,3,4,5,6,7,8,9,10), I want to write a constraint

1,2,3 → among this 3 values if one value repeated for 3 times then other two values should repeat two times
4,5 → any one value should repeat for 2 times
6,7 → any one value should repeat for 2 times
8 → should repeat for 2 times
9,10 → any one value should repeat for 2 values

In reply to bsivakumar:

The title question does not match the requirements in the body of your post. Can you clarify. Also, be “repeat” do you mean consecutively, or within a cycle of values?
Can you give some examples of expected values that would meet the constraints?

In reply to dave_59:

Hi dave,

Thanks for your response.

we have two scenarios,

The first scenario is consecutive and the result will be like below :

first_randomization → 1,1,2,2,2,3,3, 4,5,5, 6,6,7, 8,8, 9,10,10
second_randomization → 1,1,1,2,2,3,3, 4,4,5, 6,7,7, 8,8, 9,9,10

The second scenario is within a cycle of values and the result will be like below :

first_randomization → 1,2,3,4,8,6,3,7,9,4,5,7,8,4,3,9,10,1,2

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, 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