<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
John Yeung wrote:
<blockquote
cite="mid:f5e29a29-b15c-4201-82db-dd4721d501a4@r37g2000yqd.googlegroups.com"
type="cite">
<pre wrap="">On Jun 10, 1:52 am, Steven D'Aprano
<a class="moz-txt-link-rfc2396E" href="mailto:ste...@REMOVE.THIS.cybersource.com.au"><ste...@REMOVE.THIS.cybersource.com.au></a> wrote:
</pre>
<blockquote type="cite">
<pre wrap="">On Tue, 09 Jun 2009 22:21:26 -0700, John Yeung wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Therefore, to me the most up-to-date docs (which say
that uniform(a, b) returns a float in the closed
interval [a, b]) is closer to correct than before,
but still fails to point out the full subtlety of
the behavior.
</pre>
</blockquote>
<pre wrap="">Which is?
</pre>
</blockquote>
<pre wrap=""><!---->
That uniform(a, b) will return a random float in the semi-open
interval [a, b) for certain values of a and b; and in the closed
interval [a, b] for other values of a and b. (Swap a and b if a > b.)
To me, the fact that you sometimes get a semi-open interval and
sometimes a closed interval is worth noting in the docs.
John
</pre>
</blockquote>
I took the following direct from "The Python Library Reference (Release
2.6.2)" , Guido van Rossum, Fred L. Drake, Jr. editor, June 10, 2009.
On p. 216,<br>
<br>
<blockquote type="cite">Almost all module functions depend on the basic
function random(), which generates a random float uniformly<br>
in the semi-open range [0.0, 1.0). Python uses the Mersenne Twister as
the core generator. It produces 53-bit<br>
precision floats and has a period of 2**19937-1. The underlying
implementation in C is both fast and threadsafe.<br>
The Mersenne Twister is one of the most extensively tested random
number generators in existence. However,<br>
being completely deterministic, it is not suitable for all purposes,
and is completely unsuitable for cryptographic<br>
purposes.</blockquote>
The notation above means that 0 is included but 1 is not (as pointed
out by Esmail). I agree with Esmail, that it is important to know if
this is correct, since the "drawing" of pseudo RVs from other
distributions can depend on this function. <br>
<br>
The following is taken from MatLab (R2007b),<br>
<blockquote type="cite">The rand function now supports<br>
a method of random number generation called the Mersenne Twister. The
algorithm<br>
used by this method, developed by Nishimura and Matsumoto, generates
double<br>
precision values in the closed interval [2^(-53), 1-2^(-53)],<br>
with a period of (2^19937-1)/2.</blockquote>
Note, that it will not generate a 0 or 1; i.e., the interval for the
pseudo RV can be written as (0,1) or [2^(-53), 1-2^(-53)], where the
latter is more informative.<br>
<blockquote type="cite">For a full description of the Mersenne twister
algorithm, see <a class="moz-txt-link-freetext" href="http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html">http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html</a>.</blockquote>
If indeed Python 2.6.2 is using the Mersenne twister algorithm as
defined by the creators of this algorithm (go to the link given above),
then<br>
IMHO the documentation should be corrected.<br>
<br>
I hope that this helps.<br>
<br>
--V. Stokes<br>
<br>
</body>
</html>