• 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. Custom IC Design
  3. How to creat a uniform distribution in source file for Monte...

Stats

  • Locked Locked
  • Replies 8
  • Subscribers 126
  • Views 18467
  • 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

How to creat a uniform distribution in source file for Monte-Carlo simulation?

UUinfini
UUinfini over 10 years ago

Hello all,

Does anyone know how to creat a uniform distribution in source file for Monte-Carlo simulation? As the gaussian distribution is:

vary seed dist=gauss std=1

And could you recommend a document which details this part of Cadence?

Thank you very much in advance.

  • Cancel
Parents
  • Andrew Beckett
    Andrew Beckett over 8 years ago

    Laurent,

    You were asking about $rdist_uniform so I assumed you wanted a uniform distribution, not a gaussian (normal) distribution. You can use this SKILL code below if you want to generate random numbers with a gaussian distribution:

    /* abRandomNormal.il
    
    Author     A.D.Beckett
    Group      Custom IC (UK), Cadence Design Systems Ltd.
    Language   SKILL
    Date        
    Modified   
    By         
    
    Uses Box-Muller method to produce random numbers with
    a normal distribution (mean 0, std dev 1).
    
    Call abRandomNormal() multiple times to get such a sequence.
    
    ***************************************************
    
    SCCS Info: @(#) abRandomNormal.il 11/30/12.14:22:28 1.1
    
    */
    
    ;------------------------------------------------------------------------
    ; Store math constants (such as PI) as properties on this symbol
    ;------------------------------------------------------------------------
    (defMathConstants 'abRandomNormal)
    
    /***************************************************************
    *                                                              *
    *                       (abRandomNormal)                       *
    *                                                              *
    *  Return a random number with normal distribution using the   *
    *                      Box-Muller method                       *
    *                                                              *
    ***************************************************************/
    (defun abRandomNormal ()
      (let ((max (rightshift -1 1)) U V)
        (setq U (quotient (float (random max)) max))
        (setq V (quotient (float (random max)) max))
        ;--------------------------------------------------------------------
        ; could generate two independent numbers
        ; the other would use cos instead of sin
        ;--------------------------------------------------------------------
        (times (sqrt (times -2 (log U))) 
               (cos (times 2 (getqq abRandomNormal PI) V)))
        )
      )
    
    /***************************************************************
    *                                                              *
    *             (abTestRandomNormal numPoints bins)              *
    *                                                              *
    *   Function for testing - uses ViVA's plotting functions to   *
    *  produce a histogram and also compute the mean and std dev   *
    *      to ensure that with enough points it looks normal       *
    *               (e.g numPoints 100000, bins 100)               *
    *                                                              *
    ***************************************************************/
    
    (defun abTestRandomNormal (numPoints bins)
      (let (x y wave)
        (setq x (drCreateVec 'intlong numPoints))
        (setq y (drCreateVec 'double numPoints))
        (for i 0 numPoints
             (drAddElem x i)
             (drAddElem y (abRandomNormal))
             )
        (setq wave (drCreateWaveform x y))
        (awvPlotWaveform (newWindow) (list (histo wave bins nil nil)))
        (printf "Mean=%g\nStd Dev=%g\n" (average wave) (stddev wave))
        )
      )
    
    

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • Andrew Beckett
    Andrew Beckett over 8 years ago

    Laurent,

    You were asking about $rdist_uniform so I assumed you wanted a uniform distribution, not a gaussian (normal) distribution. You can use this SKILL code below if you want to generate random numbers with a gaussian distribution:

    /* abRandomNormal.il
    
    Author     A.D.Beckett
    Group      Custom IC (UK), Cadence Design Systems Ltd.
    Language   SKILL
    Date        
    Modified   
    By         
    
    Uses Box-Muller method to produce random numbers with
    a normal distribution (mean 0, std dev 1).
    
    Call abRandomNormal() multiple times to get such a sequence.
    
    ***************************************************
    
    SCCS Info: @(#) abRandomNormal.il 11/30/12.14:22:28 1.1
    
    */
    
    ;------------------------------------------------------------------------
    ; Store math constants (such as PI) as properties on this symbol
    ;------------------------------------------------------------------------
    (defMathConstants 'abRandomNormal)
    
    /***************************************************************
    *                                                              *
    *                       (abRandomNormal)                       *
    *                                                              *
    *  Return a random number with normal distribution using the   *
    *                      Box-Muller method                       *
    *                                                              *
    ***************************************************************/
    (defun abRandomNormal ()
      (let ((max (rightshift -1 1)) U V)
        (setq U (quotient (float (random max)) max))
        (setq V (quotient (float (random max)) max))
        ;--------------------------------------------------------------------
        ; could generate two independent numbers
        ; the other would use cos instead of sin
        ;--------------------------------------------------------------------
        (times (sqrt (times -2 (log U))) 
               (cos (times 2 (getqq abRandomNormal PI) V)))
        )
      )
    
    /***************************************************************
    *                                                              *
    *             (abTestRandomNormal numPoints bins)              *
    *                                                              *
    *   Function for testing - uses ViVA's plotting functions to   *
    *  produce a histogram and also compute the mean and std dev   *
    *      to ensure that with enough points it looks normal       *
    *               (e.g numPoints 100000, bins 100)               *
    *                                                              *
    ***************************************************************/
    
    (defun abTestRandomNormal (numPoints bins)
      (let (x y wave)
        (setq x (drCreateVec 'intlong numPoints))
        (setq y (drCreateVec 'double numPoints))
        (for i 0 numPoints
             (drAddElem x i)
             (drAddElem y (abRandomNormal))
             )
        (setq wave (drCreateWaveform x y))
        (awvPlotWaveform (newWindow) (list (histo wave bins nil nil)))
        (printf "Mean=%g\nStd Dev=%g\n" (average wave) (stddev wave))
        )
      )
    
    

    Regards,

    Andrew.

    • 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