random number including 1 - i.e. [0,1]
Lawrence D'Oliveiro
ldo at geek-central.gen.new_zealand
Sun Jun 14 05:32:46 EDT 2009
In message <qoteitso8ru.fsf at ruuvi.it.helsinki.fi>, Jussi Piitulainen wrote:
> Miles Kaufmann writes:
>
>> I'm curious what algorithm calls for random numbers on a closed
>> interval.
>
> The Box-Muller transform, polar form. At least Wikipedia says so.
Doesn't seem to be necessary, if I interpret the following correctly
<http://en.wikipedia.org/wiki/Box-Muller_transform#Polar_form>:
Given u and v, independent and uniformly distributed in the closed
interval [−1, +1], set s = R2 = u2 + v2. (Clearly \scriptstyle R =
\sqrt{s}.) If s = 0 or s > 1, throw u and v away and try another pair
(u, v). Continue until a pair with s in the open interval (0, 1) is
found.
Since s is supposed to be in an open interval, I don't see how it makes any
difference if u and v are chosen from an open or semiopen interval. The
probability of hitting the exact endpoints is 0, after all.
More information about the Python-list
mailing list