Jump to content

constraint dist 'others'


Recommended Posts

*,

How can I randomize with a dist and specify a weight for values not being inside a range?

 class randclass;
    rand logic [3:0] randvalue;

    function void post_randomize();
      $display("value: %0d",randvalue);
    endfunction

   constraint inside_practice {
     randvalue dist {
       [3:4] :/ 50,
       !(inside {[3:4]}) :/ 50    //<---  I try to have a sort of 'others' category here
     };
   }   
 endclass

module top;
  randclass randclass;

  initial begin
    randclass = new();
    repeat (10) begin 
      randclass.randomize();
    end
    $finish();
  end
endmodule

 

Reference:  https://www.edaplayground.com/x/cV5 

 

shaking off the rust after a SystemVerilog hiatus,

thanks

 

Link to comment
Share on other sites

  • 5 months later...
  • 4 years later...

Since the dist works only with explicit values, you can't use conditions in the distribution itself.

But, you can apply a distribution on the condition instead. This works in Questasim

constraint inside_practice {
  (randvalue inside {[3:4]}) dist {1 :/ 50, 0 :/ 50};
}   
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...