⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 module-whrandom.html

📁 一本很好的python的说明书,适合对python感兴趣的人
💻 HTML
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>5.4 whrandom -- Pseudo-random number generator</title>
<META NAME="description" CONTENT="5.4 whrandom -- Pseudo-random number generator">
<META NAME="keywords" CONTENT="lib">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="STYLESHEET" href="lib.css" tppabs="http://www.python.org/doc/current/lib/lib.css">
<LINK REL="next" href="module-bisect.html" tppabs="http://www.python.org/doc/current/lib/module-bisect.html">
<LINK REL="previous" href="module-random.html" tppabs="http://www.python.org/doc/current/lib/module-random.html">
<LINK REL="up" href="misc.html" tppabs="http://www.python.org/doc/current/lib/misc.html">
<LINK REL="next" href="module-bisect.html" tppabs="http://www.python.org/doc/current/lib/module-bisect.html">
</head>
<body>
<DIV CLASS="navigation"><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="rng-objects.html" tppabs="http://www.python.org/doc/current/lib/rng-objects.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
  alt="Previous Page" width="32"></A></td>
<td><A href="misc.html" tppabs="http://www.python.org/doc/current/lib/misc.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
  alt="Up One Level" width="32"></A></td>
<td><A href="module-bisect.html" tppabs="http://www.python.org/doc/current/lib/module-bisect.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
  alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
  alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
  alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
  alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="rng-objects.html" tppabs="http://www.python.org/doc/current/lib/rng-objects.html">5.3.1 The Random Number</A>
<b class="navlabel">Up:</b> <a class="sectref" href="misc.html" tppabs="http://www.python.org/doc/current/lib/misc.html">5. Miscellaneous Services</A>
<b class="navlabel">Next:</b> <a class="sectref" href="module-bisect.html" tppabs="http://www.python.org/doc/current/lib/module-bisect.html">5.5 bisect  </A>
<br><hr></DIV>
<!--End of Navigation Panel-->

<H1><A NAME="SECTION007400000000000000000">
5.4 <tt class="module">whrandom</tt> --
         Pseudo-random number generator</A>
</H1>

<P>


<P>
This module implements a Wichmann-Hill pseudo-random number generator
class that is also named <tt class="class">whrandom</tt>.  Instances of the
<tt class="class">whrandom</tt> class conform to the Random Number Generator
interface described in section <A href="rng-objects.html#rng-objects" tppabs="http://www.python.org/doc/current/lib/rng-objects.html#rng-objects">5.3.1</A>.  They also offer the 
following method, specific to the Wichmann-Hill algorithm:

<P>
<dl><dt><b><a name='l2h-747'><tt class='method'>seed</tt></a></b> (<big>[</big><var>x, y, z</var><big>]</big>)
<dd>
  Initializes the random number generator from the integers <var>x</var>,
  <var>y</var> and <var>z</var>.  When the module is first imported, the random
  number is initialized using values derived from the current time.
  If <var>x</var>, <var>y</var>, and <var>z</var> are either omitted or <code>0</code>, the 
  seed will be computed from the current system time.  If one or two
  of the parameters are <code>0</code>, but not all three, the zero values
  are replaced by ones.  This causes some apparently different seeds
  to be equal, with the corresponding result on the pseudo-random
  series produced by the generator.
</dl>

<P>
<dl><dt><b><a name='l2h-748'><tt class='function'>choice</tt></a></b> (<var>seq</var>)
<dd>
Chooses a random element from the non-empty sequence <var>seq</var> and returns it.
</dl>

<P>
<dl><dt><b><a name='l2h-749'><tt class='function'>randint</tt></a></b> (<var>a, b</var>)
<dd>
Returns a random integer <var>N</var> such that <code><var>a</var>&lt;=<var>N</var>&lt;=<var>b</var></code>.
</dl>

<P>
<dl><dt><b><a name='l2h-750'><tt class='function'>random</tt></a></b> ()
<dd>
Returns the next random floating point number in the range [0.0 ... 1.0).
</dl>

<P>
<dl><dt><b><a name='l2h-751'><tt class='function'>seed</tt></a></b> (<var>x, y, z</var>)
<dd>
Initializes the random number generator from the integers <var>x</var>,
<var>y</var> and <var>z</var>.  When the module is first imported, the random
number is initialized using values derived from the current time.
</dl>

<P>
<dl><dt><b><a name='l2h-752'><tt class='function'>uniform</tt></a></b> (<var>a, b</var>)
<dd>
Returns a random real number <var>N</var> such that <code><var>a</var>&lt;=<var>N</var>&lt;<var>b</var></code>.
</dl>

<P>
When imported, the <tt class="module">whrandom</tt> module also creates an instance of
the <tt class="class">whrandom</tt> class, and makes the methods of that instance
available at the module level.  Therefore one can write either 
<code>N = whrandom.random()</code> or:

<P>
<dl><dd><pre class="verbatim">
generator = whrandom.whrandom()
N = generator.random()
</pre></dl>

<P>
Note that using separate instances of the generator leads to
independent sequences of pseudo-random numbers.

<P>
<div class='seealso'>
  <p class='heading'><b>See Also:</b></p>

  <dl compact class="seemodule">
    <dt>Module <b><tt class='module'><a href="module-random.html" tppabs="http://www.python.org/doc/current/lib/module-random.html">random</a></tt>:</b>
    <dd>Generators for various random distributions and
                     documentation for the Random Number Generator
                     interface.
  </dl>
  <div class="seetext"><p>Wichmann, B. A. &amp; Hill, I. D., ``Algorithm AS 183: 
           An efficient and portable pseudo-random number generator'',
           <em class='citetitle'
 >Applied Statistics</em> 31 (1982) 188-190.</div>
</div>

<DIV CLASS="navigation"><p><hr><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="rng-objects.html" tppabs="http://www.python.org/doc/current/lib/rng-objects.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
  alt="Previous Page" width="32"></A></td>
<td><A href="misc.html" tppabs="http://www.python.org/doc/current/lib/misc.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
  alt="Up One Level" width="32"></A></td>
<td><A href="module-bisect.html" tppabs="http://www.python.org/doc/current/lib/module-bisect.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
  alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
  alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
  alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
  alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="rng-objects.html" tppabs="http://www.python.org/doc/current/lib/rng-objects.html">5.3.1 The Random Number</A>
<b class="navlabel">Up:</b> <a class="sectref" href="misc.html" tppabs="http://www.python.org/doc/current/lib/misc.html">5. Miscellaneous Services</A>
<b class="navlabel">Next:</b> <a class="sectref" href="module-bisect.html" tppabs="http://www.python.org/doc/current/lib/module-bisect.html">5.5 bisect  </A>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
<hr>See <i><a href="about.html" tppabs="http://www.python.org/doc/current/lib/about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -