• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Functional Verification
  3. A question about randomize()

Stats

  • Locked Locked
  • Replies 3
  • Subscribers 64
  • Views 13426
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

A question about randomize()

archive
archive over 17 years ago

In the following code,  when BCDA.randomize() is excuted, it seems to me methd ADD() is also excuted at same time even though it is not explicitly called. How does randomize() work exactly? Thanks in advance!

//BCD addition testbench
//www.asichowto.com

module BCDAddition_tb();

class BCDAdd;
    rand logic[3:0] BCD1,BCD2;
    logic[7:0] result;
    
    function new();
        BCD1=0;
        BCD2=0;
    endfunction
    
    constraint c
    {
        BCD1
        BCD2
    }

    function void ADD();
        result=BCD1+BCD2;
        if(result>9)
           result=result+6;
    endfunction
endclass



BCDAdd BCDA;
logic[3:0] b1,b2;
logic[7:0] r;

BCDAddition U(b1,b2,r);

initial
begin
    repeat(10)
    begin
        BCDA=new;
        if(BCDA.randomize())
        begin
            b1=BCDA.BCD1;
            b2=BCDA.BCD2;
//            BCDA.ADD();
            if(r!=BCDA.result)
            begin
                $display("Class:  BCD1=%d BCD2=%d result=%d", BCDA.BCD1,BCDA.BCD2,BCDA.result);
                $display("Module: BCD1=%d BCD2=%d result=%d", b1,b2,r);
            end
        end
        #10ns;
    end
end
endmodule


Originally posted in cdnusers.org by jt27560
  • Cancel
Parents
  • archive
    archive over 17 years ago

    Thanks, Steve.

    It does not display anything whether I comment out BCDA.ADD() or not, which gives me an impression that ADD() is executed too when randomize is executed.
    I should use !== instead of !=. And should put a delay right after ADD();


    Originally posted in cdnusers.org by jt27560
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • archive
    archive over 17 years ago

    Thanks, Steve.

    It does not display anything whether I comment out BCDA.ADD() or not, which gives me an impression that ADD() is executed too when randomize is executed.
    I should use !== instead of !=. And should put a delay right after ADD();


    Originally posted in cdnusers.org by jt27560
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Children
No Data

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information