]> granicus.if.org Git - python/commitdiff
Add punctuation mark; add some examples
authorAndrew M. Kuchling <amk@amk.ca>
Thu, 27 Jul 2006 19:07:29 +0000 (19:07 +0000)
committerAndrew M. Kuchling <amk@amk.ca>
Thu, 27 Jul 2006 19:07:29 +0000 (19:07 +0000)
Doc/lib/librandom.tex

index 6c2f7101257a9f1e0b7e30399f3459eca6fbb374..c6b88469a376c711ce78e76d69bd193b594c92b4 100644 (file)
@@ -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