[Python-checkins] r50873 - python/trunk/Doc/lib/librandom.tex
andrew.kuchling
python-checkins at python.org
Thu Jul 27 21:07:30 CEST 2006
Author: andrew.kuchling
Date: Thu Jul 27 21:07:29 2006
New Revision: 50873
Modified:
python/trunk/Doc/lib/librandom.tex
Log:
Add punctuation mark; add some examples
Modified: python/trunk/Doc/lib/librandom.tex
==============================================================================
--- python/trunk/Doc/lib/librandom.tex (original)
+++ python/trunk/Doc/lib/librandom.tex Thu Jul 27 21:07:29 2006
@@ -236,7 +236,7 @@
\var{beta} is the shape parameter.
\end{funcdesc}
-Alternative Generators
+Alternative Generators:
\begin{classdesc}{WichmannHill}{\optional{seed}}
Class that implements the Wichmann-Hill algorithm as the core generator.
@@ -267,6 +267,30 @@
\versionadded{2.4}
\end{classdesc}
+Examples of basic usage:
+
+\begin{verbatim}
+>>> random.random() # Random float x, 0.0 <= x < 1.0
+0.37444887175646646
+>>> random.uniform(1, 10) # Random float x, 1.0 <= x < 10.0
+1.1800146073117523
+>>> random.randint(1, 10) # Integer from 1 to 10, endpoints included
+7
+>>> random.randrange(0, 101, 2) # Even integer from 0 to 100
+26
+>>> random.choice('abcdefghij') # Choose a random element
+'c'
+
+>>> items = [1, 2, 3, 4, 5, 6, 7]
+>>> random.shuffle(items)
+>>> items
+[7, 3, 2, 5, 6, 4, 1]
+
+>>> random.sample([1, 2, 3, 4, 5], 3) # Choose 3 elements
+[4, 1, 5]
+
+\end{verbatim}
+
\begin{seealso}
\seetext{M. Matsumoto and T. Nishimura, ``Mersenne Twister: A
623-dimensionally equidistributed uniform pseudorandom
More information about the Python-checkins
mailing list