Thomas A. Russ <firstname.lastname@example.org> wrote:
| email@example.com (Rob Warnock) writes:
| > This should be safe from blowups [though still not from negative IQs],
| > though it biases the results a tiny bit [a really, *really* tiny bit!]:
| > (defun random-IQ-score ()
| > (+ 100 (* 15 (sqrt (* -2 (log (+ (random 1d0)
| > least-positive-double-float))))
| > (cos (* 2 pi (random 1d0))))))
| Does it really bias it any more than before?
| The reason is because the range of (random 1.0d0) is actually [0.0, 1.0)
| and not [0.0, 1.0], and this is presumably being shifted slightly to
| to (0.0, 1.0), since the least-positive-double-float won't be large
| enough to change the value of 1.0d0 when added. ...
Actually, as Tamas Papp pointed out, the correct domain for the
Box-Muller algorithm is (0.0, 1.0] anyway, so that "the right thing"
[after Scott corrected Tamas's typo] is to use (- 1d0 (random 1d0))
instead, and so now we're back to three lines:
(defun random-IQ-score ()
(+ 100 (* 15 (sqrt (* -2 (log (- 1d0 (random 1d0)))))
(cos (* 2 pi (random 1d0))))))
p.s. Scott also suggested using the SIN result rather than COS,
but you're going to lose one point from the range in any case.
I don't see that it matters from which end.
Rob Warnock <firstname.lastname@example.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607