Re: C-faq q13.20



Ben Bacarisse <ben.usenet@xxxxxxxxx> writes:

"Thomas Lumley" <thomas@xxxxxxxxxxx> writes:

One of the examples in q13.20 in the FAQ
(http://c-faq.com/lib/sd16.html, linked from
http://c-faq.com/lib/gaussian.html) seems to be wrong.

The full code is at that link. The part of the code that actually does
the work is

y = (double) rand() / (RAND_MAX + 1.0); /* 0.0 <= y < 1.0 */
bin = (y < 0.5) ? 0 : 1;
y = fabs(y - 1.0); /* 0.0 < y <= 1.0 */
y = std_dev * sqrt((-2.0) * log(y));

return bin ? (mean + y) : (mean - y);

Indeed. The above will not produce a distribution that is symmetric
about "mean" because the decision as to which side of the mean we
return is correlated to the size of the uniform random number y.
<other stuff of mine snipped>
I should add that even then I don't think the result is normally
distributed (though it will at least be symmetrical).

Drat! Posted by mistake. After writing, I decided that the original
linked code was so broken (this last phrase of mine is far too week --
the result is *definitely* not Gaussian) that it was best to say
nothing!

Anyway, having said more the nothing, the best thing to say is to
suggest the link be removed lest anyone try to use it. (And don't use
the above unless you want some strange, unspecified, symmetric
distribution or numbers!)

--
Ben.
.



Relevant Pages

  • Re: Hard Drive Space
    ... of the distribution, ... security problems it had over the life of the distribution. ... in the space, either the box is 0wn3d, or you have a process that is writing ... If you don't recall removing some log file manually, ...
    (linux.redhat)
  • Re: Government Crap
    ... about producing too many because of problems of storage and distribution! ... go with the ancient Celts - nothing in writing. ...
    (uk.business.agriculture)
  • Markov Chain stationarity?
    ... Hey kiki - what with you and "lose-mind Lucy" writing very similar queries ... at almost exactly the same time, I expect someone somewhere is teaching ... and it is also the unique stationary distribution! ...
    (sci.math)
  • Markov Chain stationarity?
    ... Hey kiki - what with you and "lose-mind Lucy" writing very similar queries ... at almost exactly the same time, I expect someone somewhere is teaching ... and it is also the unique stationary distribution! ...
    (sci.stat.math)
  • Re: Distance Between 2 Randomly-chosen Points on a Sphere
    ... the unit sphere in R^3. ... Define a probability distribution P on S ... While one might claim that the phrase "randomly selected" is ambiguous, ... be interpreted as indicating a uniform distribution on the sample space. ...
    (sci.math)