Issue of numerous rand variable in constraint

Hi all:
when there are numerous rand variable in constraint:


class xaction;
    rand int num[5];
         
    constraint c_num {
        foreach (num[i]) {
            if (i > 0 ) { 
                num[i-1] < num[i];
            }   
            num[i] inside {[0:9]};
        }   
    }       
endclass : xaction
         
module top;
    xaction x;
         
    int last_is_9;
    int repeat_num;
         
    initial begin
        repeat_num = 50000;             
        repeat (repeat_num) begin
            x = new;
            x.randomize();
            if (x.num[4] == 9) last_is_9 ++; 
        end 
       $display("last_is_9 hits: %0d/%0d", last_is_9, repeat_num); 
    end  
endmodule

  

output:
last_is_9 hits: 25260/50000

As we expected, the result in array is uniform distribution, but the posibility of last element x.num[4] is 9 with above 50%.
How to modify the constraint (don’t use user-defined function in post_randomize)can make the x.num[4] inside [4:9] with a reasonable posibility?

Thanks!

If by reasonable you mean you want an even distribution of the values 4-9 in x.num[4], then add a dist constraint.

   constraint c_dist {num[4] dist {[4:9] :=1};}

In reply to dave_59:

Thanks for your help!