• 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. Is there a way to generate Gaussian random numbers in Ocean...

Stats

  • Locked Locked
  • Replies 5
  • Subscribers 126
  • Views 4712
  • 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

Is there a way to generate Gaussian random numbers in Ocean/Skill?

CADcasualty
CADcasualty over 7 years ago

I didn't find anything in the documentation or forums - I was wondering if there is an available mathematical function that I could use in an Ocean script whereby I pass in a mean and sigma and get back a random number within that specified normal distribution. I would have thought for sure something like that would be available but I just can't seem to find it...

  • Cancel
  • mschw
    mschw over 7 years ago

    Hi,

    i think you can create using random() a (nearly ?) uniform distributed random variable. By using two uniform distributed random variables and Box-Muller transform you can create two normal distributed variables. By scaling with sigma and mu you can get your desired normal distribution. Please note that I haven't checked it myself.

    Kind regards,

    Matthias

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • CADcasualty
    CADcasualty over 7 years ago in reply to mschw

    Yes - agreed that you can always use existing box-car random numbers and, if you write your own function, make something that yields a a normal distribution. However, it's such a fundamental thing you'd reckon the function would exist somewhere within the Skill/Ocean world. You could also write your own code to do logarithms and trigonometric functions, but happily they exist already (so OK, maybe that comment was a little harsh)...

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 7 years ago in reply to CADcasualty

    I wouldn't class this the same way as log or trig functions, since those are rather more fundamental (for example, those are in the C maths library, but a Gaussian random number generator isn't AFAIK). However, I have written a function to do this a while back (using the Box-Muller method) - which can be found in this post.

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • CADcasualty
    CADcasualty over 7 years ago in reply to Andrew Beckett

    I actually did find your code by searching further and am already using it successfully - so yet another thank you for your efforts! I did mean to respond to this post after I found it but forgot. I also took a look at your code (presumably written in Lisp or something) and couldn't understand a bloody word of it.

    Captain's pesronal log:  Bummer that Cadence has to use such an ancient, miserable, obtuse language like that. I think that's how their applications engineers get 100% guaranteed job security ;-).

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 7 years ago in reply to CADcasualty
    CADcasualty said:
    Bummer that Cadence has to use such an ancient, miserable, obtuse language like that

    Yes, LISP is an old language, but it's not necessarily obtuse (and I'm not being overly defensive here). I tend to write my code in LISP style because when I first started writing SKILL (before I worked for Cadence), I had written a lot of C and the fact that the C-style wasn't quite C tended to cause me to make mistakes, plus it encouraged me to think using LISP approaches to problems. I'd also written some LISP at University too...

    Using the pp() function you can easily dump out the code in a more familiar C style. In fact using this code you can convert from LISP to C style:

    procedure(abConvToC(inFile outFile)
      let((inPort outPort (data t))
        inPort=infile(inFile)
        outPort=outfile(outFile)
        while(data
          while((data=lineread(inPort))==t t)
          foreach(form data
            pprint(form outPort)
            newline(outPort)
          )
        )
        close(inPort)
        close(outPort)
      )
    )

    So that means the code (I didn't bother with the test function) above is:

    defMathConstants('abRandomNormal)
    defun(abRandomNormal nil 
        let((max((-1 >> 1)) U V) 
    	(U = (float(random(max)) / max)) 
    	(V = (float(random(max)) / max)) 
    	(sqrt((-2 * log(U))) * cos((2 * (abRandomNormal.PI) * V)))
        )
    )

    The pretty printer puts a few extra brackets than strictly necessary, but hopefully it's a bit easier to understand. Probably the only complicated bit still is that max is initialised in the let to be -1 >> 1 which is the maximum integer (I could have used abRandomNormal.INT_MAX instead - defMathConstants defines that usefully as well as defining PI).

    I completely get that people don't necessarily find the LISP format easy to understand, which is why I write code intended as examples (i.e. something you're going to modify or base your own code upon) in C-style. However, for code that is likely to be used as-is as a library function, I write it the way I find more natural. I would say that most AEs in Cadence don't write using LISP style though.

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel

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