Thomas A. Russ <tar@sevak.isi.edu> wrote:
+
 rpw3@rpw3.org (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 randomIQscore ()
 > (+ 100 (* 15 (sqrt (* 2 (log (+ (random 1d0)
 > leastpositivedoublefloat))))
 > (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 leastpositivedoublefloat 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
BoxMuller 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 randomIQscore ()
(+ 100 (* 15 (sqrt (* 2 (log ( 1d0 (random 1d0)))))
(cos (* 2 pi (random 1d0))))))
Rob
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 <rpw3@rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)5722607