Quantcast
Channel: Jason Andrews Blog
Viewing all articles
Browse latest Browse all 33813

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

$
0
0
[quote user="CADcasualty"]Bummer that Cadence has to use such an ancient, miserable, obtuse language like that[/quote] 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.

Viewing all articles
Browse latest Browse all 33813

Trending Articles