Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!willett!ForthNet From: ForthNet@willett.UUCP (ForthNet articles from GEnie) Newsgroups: comp.lang.forth Subject: Mathematical routines Message-ID: <672.UUL1.3#5129@willett.UUCP> Date: 18 Mar 90 00:23:21 GMT Organization: Latest link in the ForthNet chain. (Pgh, PA) Lines: 51 Date: 03-15-90 (22:47) Number: 3034 (Echo) To: HARV Refer#: 3027 From: DOUG SCHIFFER Read: NO Subj: MATHEMATICAL ROUTINES Status: PUBLIC MESSAGE #define LOCAL static #define BOOL int #define TRUE 1 #define FALSE 0 double random(); /* a function which returns a uniform random * number in the range [0.0 - 1.0] */ /****************************************************************/ double randnorm() /* Return a normally distributed random value with zero mean and unit standard deviation. */ /*--------------------------------------------------------------*/ { LOCAL BOOL first = 1; double d, v1, v2; if (first--) { do { v1 = 2.0 * random() - 1.0; v2 = 2.0 * random() - 1.0; /* v1 and v2 are each uniform on [-1, 1] */ d = v1 * v1 + v2 * v2; } while ((d <= 0.0) OR (d >= 1.0)); /* now, the point (v1, v2) is uniform inside the unit * circle, excluding the origin. */ d = sqrt(-2.0 * log(d) / d); v1 *= d; v2 *= d; return (v1); } else { first = TRUE; return (v2); } } --- * Via ProDoor 3.1R Of COURSE I'm egotistical - and DAMN PROUD of it, too! NET/Mail : Kadet PCB, Camden,NY, (315)245-3815 * MetroLink Regional Hub ----- This message came from GEnie via willett through a semi-automated process. Report problems to: 'uunet!willett!dwp' or 'willett!dwp@gateway.sei.cmu.edu'