summaryrefslogtreecommitdiffstats
path: root/Doc/lib/librandom.tex
diff options
context:
space:
mode:
Diffstat (limited to 'Doc/lib/librandom.tex')
-rw-r--r--Doc/lib/librandom.tex26
1 files changed, 25 insertions, 1 deletions
diff --git a/Doc/lib/librandom.tex b/Doc/lib/librandom.tex
index 6c2f710..c6b8846 100644
--- a/Doc/lib/librandom.tex
+++ b/Doc/lib/librandom.tex
@@ -236,7 +236,7 @@ these equations can be found in any statistics text.
\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 @@ called.
\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