Weird behavior when randomizing dynamic array

I’m trying to randomize a dynamic array as shown below. What I want to achieve is to randomize the array (burst_len) with given size (burst_cnt from plusarg), and all elements in the array add up to a give value (instr_cnt from plusarg). Each element should be larger than or equal to 2.

The following code couldn’t give me what I want. I need to add an extra constraint for each element. Couldn’t figure out why this constraint is needed.


    int burst_cnt = 10;
    int instr_cnt = 100;
    int unsigned burst_len[];

    std::randomize(burst_len) with {
      foreach (burst_len[i]) {
        burst_len[i] >= 2;
        **//burst_len[i] <= instr_cnt;**
      }
      burst_len.sum() == instr_cnt;
      burst_len.size() == burst_cnt;
    };
    for (int i=0; i<burst_len.size(); i++)
      $display("burst_len[%0d] = %0d", i, burst_len[i]);

In reply to eda2k4:

Without extra constraint, I get the following:
burst_len[0] = 1584258998
burst_len[1] = 3134088755
burst_len[2] = 828825450
burst_len[3] = 4111691712
burst_len[4] = 1968018003
burst_len[5] = 824687916
burst_len[6] = 1008475836
burst_len[7] = 1491683716
burst_len[8] = 1319840510
burst_len[9] = 908298388

With extra (and unnecessary IMO) constraint, I get the right result:
burst_len[0] = 5
burst_len[1] = 3
burst_len[2] = 16
burst_len[3] = 39
burst_len[4] = 2
burst_len[5] = 3
burst_len[6] = 2
burst_len[7] = 26
burst_len[8] = 2
burst_len[9] = 2

In reply to eda2k4:

You should try summing those 10 numbers and see what you get.

In reply to dave_59:

17179869284…so it is over 32-bit. But why solver thinks it is the solution?

Ok…it is 0x400000064. And 0x64 is 100?

In reply to eda2k4:

Correct. It is a solution, just not the one you were expecting. You need to add constraints to narrow the solution space, or choose data types and expressions that won’t overflow.