in reply to Re: How do I get random numbers that follow standard distribution?
in thread How do I get random numbers that follow standard distribution?

This page claims that the while condition should be } while ($w>=1 or $w==0);

Caution: Contents may have been coded under pressure.
  • Comment on Re: Answer: How do I get random numbers that follow standard distribution?
  • Download Code

Replies are listed 'Best First'.
Re^2: Answer: How do I get random numbers that follow standard distribution?
by hv (Prior) on Feb 18, 2005 at 11:56 UTC

    $w == 0 will occur only when $u1 == $u2 == 1/2, which will happen rarely enough that I can't see it skewing the results noticeably - even if you only have 32-bit random numbers, you'll hit this case only 1.27 in 2^64 times.

    (That 1.27 is based on my rusty attempts to calculate how many times we loop until we get $w < 1. I think the probability of a success is arcsin(1)/2, which is about 0.78.)

    Hugo