summaryrefslogtreecommitdiffstats
path: root/Doc/lib/librandom.tex
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2003-10-05 09:09:15 (GMT)
committerRaymond Hettinger <python@rcn.com>2003-10-05 09:09:15 (GMT)
commit2f726e9093381572b21edbfc42659ea89fbdf686 (patch)
tree9625e748344e1709fc69a8b98298efdd602b4cc2 /Doc/lib/librandom.tex
parent5c68ef04b7f0c0c1d342647a7db2d3f76637d3fa (diff)
downloadcpython-2f726e9093381572b21edbfc42659ea89fbdf686.zip
cpython-2f726e9093381572b21edbfc42659ea89fbdf686.tar.gz
cpython-2f726e9093381572b21edbfc42659ea89fbdf686.tar.bz2
SF bug #812202: randint is always even
* Added C coded getrandbits(k) method that runs in linear time. * Call the new method from randrange() for ranges >= 2**53. * Adds a warning for generators not defining getrandbits() whenever they have a call to randrange() with too large of a population.
Diffstat (limited to 'Doc/lib/librandom.tex')
-rw-r--r--Doc/lib/librandom.tex12
1 files changed, 12 insertions, 0 deletions
diff --git a/Doc/lib/librandom.tex b/Doc/lib/librandom.tex
index 5483ff2..2b686ec 100644
--- a/Doc/lib/librandom.tex
+++ b/Doc/lib/librandom.tex
@@ -41,6 +41,10 @@ Class \class{Random} can also be subclassed if you want to use a
different basic generator of your own devising: in that case, override
the \method{random()}, \method{seed()}, \method{getstate()},
\method{setstate()} and \method{jumpahead()} methods.
+Optionally, a new generator can supply a \method{getrandombits()}
+method --- this allows \method{randrange()} to produce selections
+over an arbitrarily large range.
+\versionadded[the \method{getrandombits()} method]{2.4}
As an example of subclassing, the \module{random} module provides
the \class{WichmannHill} class which implements an alternative generator
@@ -92,6 +96,14 @@ Bookkeeping functions:
separated by many steps.]{2.3}
\end{funcdesc}
+\begin{funcdesc}{getrandbits}{k}
+ Returns a python \class{long} int with \var{k} random bits.
+ This method is supplied with the MersenneTwister generator and some
+ other generators may also provide it as an optional part of the API.
+ When available, \method{getrandbits()} enables \method{randrange()}
+ to handle arbitrarily large ranges.
+ \versionadded{2.4}
+\end{funcdesc}
Functions for integers: