1
2
3
4
5
6
7
8
9
|
<h3 class="section">Random Numbers</h3> <p>A deterministic computer program cannot generate true random numbers. For most purposes, <em>pseudo-random numbers</em> suffice. A series of pseudo-random numbers is generated in a deterministic fashion. The numbers are not truly random, but they have certain properties that mimic a random series. For example, all possible values occur equally often in a pseudo-random series. </p> <p>Pseudo-random numbers are generated from a <em>seed value</em>. Starting from any given seed, the <code>random</code> function always generates the same sequence of numbers. By default, Emacs initializes the random seed at startup, in such a way that the sequence of values of <code>random</code> (with overwhelming likelihood) differs in each Emacs run. </p> <p>Sometimes you want the random number sequence to be repeatable. For example, when debugging a program whose behavior depends on the random number sequence, it is helpful to get the same behavior in each program run. To make the sequence repeat, execute <code>(random "")</code>. This sets the seed to a constant value for your particular Emacs executable (though it may differ for other Emacs builds). You can use other strings to choose various seed values. </p> <dl> <dt id="random">Function: <strong>random</strong> <em>&optional limit</em>
</dt> <dd>
<p>This function returns a pseudo-random integer. Repeated calls return a series of pseudo-random integers. </p> <p>If <var>limit</var> is a positive integer, the value is chosen to be nonnegative and less than <var>limit</var>. Otherwise, the value might be any fixnum, i.e., any integer from <code>most-negative-fixnum</code> through <code>most-positive-fixnum</code> (see <a href="integer-basics">Integer Basics</a>). </p> <p>If <var>limit</var> is <code>t</code>, it means to choose a new seed as if Emacs were restarting, typically from the system entropy. On systems lacking entropy pools, choose the seed from less-random volatile data such as the current time. </p> <p>If <var>limit</var> is a string, it means to choose a new seed based on the string’s contents. </p> </dd>
</dl><div class="_attribution">
<p class="_attribution-p">
Copyright © 1990-1996, 1998-2022 Free Software Foundation, Inc. <br>Licensed under the GNU GPL license.<br>
<a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Random-Numbers.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Random-Numbers.html</a>
</p>
</div>
|