Constraint

when I randomize a variable I don’t want 1 to 7 and 8 to 15 has to come in cyclic order, I tried with weighted distribution constraint. but it not working. Could u please let me know how to make this logic?

In reply to anvesh dangeti:

when I randomize a variable I don’t want 1 to 7 and 8 to 15 has to come in cyclic order, I tried with weighted distribution constraint. but it not working. Could u please let me know how to make this logic?

Hi,

Can you elaborate your query? An example will help.

Example:

class packet;
  rand bit [3:0] addr;
 
  constraint addr_range { addr dist { [1:7] := 0,[8:15] := 1 }; }
endclass
 
module constr_dist;
  initial begin
    packet pkt;
    pkt = new();
    $display("------------------------------------");
    repeat(10) begin
      pkt.randomize();
      $display("\taddr = %0d",pkt.addr);
    end
    $display("------------------------------------");
  end
endmodule

when I randomizing I don’t want to 1 to 7 values i.e. the weight of “1” to “7” is set to “zero” I want only 8 to 15 in cyclic order. i.e. the weight set to “one”

but output get I am not expecting. Please suggest me correct way.

In reply to anvesh dangeti:

Since you want cyclic behavior use randc


class packet;
  randc bit [3:0] addr;
 
  constraint addr_range { addr  inside { [8:15] } ;  }
  //  You  won't  see  values  0 to 7
 
endclass


the above logic is good to generate required values.
but why below logic is not working:

class packet;
  rand bit [3:0] addr;
 
  constraint addr_range { addr dist { [1:7] := 0,[8:15] := 1 }; }
endclass

In reply to anvesh dangeti:

randc has cyclic behavior whereas dist constraint has no such behavior .

based on your constraint , the solver has equal probability to select from values
8 to 15 with equal probability . Which means values may be repeated hence
No - cyclic behavior

Hope this explanation helps