diff options
| author | Craig Jennings <c@cjennings.net> | 2025-08-14 22:58:58 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2025-08-14 22:58:58 -0500 |
| commit | 82ba818ff456bcd6d56a06226e3f27e98fbb55c3 (patch) | |
| tree | 158cfc17b2f644a10f063cb546752cfaae12c97f /devdocs/c/numeric%2Frandom%2Fsrand.html | |
| parent | 9278ddd4ea1a8b1a4c1edaa8894516e3f48d245b (diff) | |
| download | dotemacs-82ba818ff456bcd6d56a06226e3f27e98fbb55c3.tar.gz dotemacs-82ba818ff456bcd6d56a06226e3f27e98fbb55c3.zip | |
removing all downloaded devdocs files
Diffstat (limited to 'devdocs/c/numeric%2Frandom%2Fsrand.html')
| -rw-r--r-- | devdocs/c/numeric%2Frandom%2Fsrand.html | 38 |
1 files changed, 0 insertions, 38 deletions
diff --git a/devdocs/c/numeric%2Frandom%2Fsrand.html b/devdocs/c/numeric%2Frandom%2Fsrand.html deleted file mode 100644 index b51663b0..00000000 --- a/devdocs/c/numeric%2Frandom%2Fsrand.html +++ /dev/null @@ -1,38 +0,0 @@ - <h1 id="firstHeading" class="firstHeading">srand</h1> <table class="t-dcl-begin"> <tr class="t-dsc-header"> <th> Defined in header <code><stdlib.h></code> </th> <th> </th> <th> </th> </tr> <tr class="t-dcl"> <td class="t-dcl-nopad"> <pre data-language="c">void srand( unsigned seed );</pre> -</td> <td class="t-dcl-nopad"> </td> <td class="t-dcl-nopad"> </td> </tr> </table> <p>Seeds the pseudo-random number generator used by <code><a href="rand" title="c/numeric/random/rand">rand()</a></code> with the value <code>seed</code>.</p> -<p>If <code>rand()</code> is used before any calls to <code>srand()</code>, <code>rand()</code> behaves as if it was seeded with <code>srand(1)</code>.</p> -<p>Each time <code>rand()</code> is seeded with the same <code>seed</code>, it must produce the same sequence of values.</p> -<p><code>srand()</code> is not guaranteed to be thread-safe.</p> -<h3 id="Parameters"> Parameters</h3> <table class="t-par-begin"> <tr class="t-par"> <td> seed </td> <td> - </td> <td> the seed value </td> -</tr> -</table> <h3 id="Return_value"> Return value</h3> <p>(none)</p> -<h3 id="Notes"> Notes</h3> <p>Generally speaking, the pseudo-random number generator should only be seeded once, before any calls to <code>rand()</code>, and the start of the program. It should not be repeatedly seeded, or reseeded every time you wish to generate a new batch of pseudo-random numbers.</p> -<p>Standard practice is to use the result of a call to <code><a href="http://en.cppreference.com/w/c/chrono/time"><span class="kw513">time</span></a><span class="br0">(</span><span class="nu0">0</span><span class="br0">)</span></code> as the seed. However, <code>time()</code> returns a <code><a href="../../chrono/time_t" title="c/chrono/time t">time_t</a></code> value, and <code>time_t</code> is not guaranteed to be an integral type. In practice, though, every major implementation defines <code>time_t</code> to be an integral type, and this is also what POSIX requires.</p> -<h3 id="Example"> Example</h3> <div class="t-example"> <div class="c source-c"><pre data-language="c">#include <stdio.h> -#include <stdlib.h> -#include <time.h> - -int main(void) -{ - srand(time(NULL)); //use current time as seed for random generator - int random_variable = rand(); - printf("Random value on [0,%d]: %d\n", RAND_MAX, random_variable); -}</pre></div> <p>Possible output:</p> -<div class="text source-text"><pre data-language="c">Random value on [0 2147483647]: 1373858591</pre></div> </div> <h3 id="References"> References</h3> <ul> -<li> C17 standard (ISO/IEC 9899:2018): </li> -<ul><li> 7.22.2.2 The srand function (p: 252-253) </li></ul> -<li> C11 standard (ISO/IEC 9899:2011): </li> -<ul><li> 7.22.2.2 The srand function (p: 346-347) </li></ul> -<li> C99 standard (ISO/IEC 9899:1999): </li> -<ul><li> 7.20.2.2 The srand function (p: 312-313) </li></ul> -<li> C89/C90 standard (ISO/IEC 9899:1990): </li> -<ul><li> 4.10.2.2 The srand function </li></ul> -</ul> <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td> <div><a href="rand" title="c/numeric/random/rand"> <span class="t-lines"><span>rand</span></span></a></div> </td> <td> generates a pseudo-random number <br> <span class="t-mark">(function)</span> </td> -</tr> <tr class="t-dsc"> <td> <div><a href="rand_max" title="c/numeric/random/RAND MAX"> <span class="t-lines"><span>RAND_MAX</span></span></a></div> </td> <td> maximum possible value generated by <code><a href="http://en.cppreference.com/w/c/numeric/random/rand"><span class="kw740">rand</span></a><span class="br0">(</span><span class="br0">)</span></code> <br> <span class="t-mark">(macro constant)</span> </td> -</tr> <tr class="t-dsc"> <td colspan="2"> <span><a href="https://en.cppreference.com/w/cpp/numeric/random/srand" title="cpp/numeric/random/srand">C++ documentation</a></span> for <code>srand</code> </td> -</tr> </table> <div class="_attribution"> - <p class="_attribution-p"> - © cppreference.com<br>Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.<br> - <a href="https://en.cppreference.com/w/c/numeric/random/srand" class="_attribution-link">https://en.cppreference.com/w/c/numeric/random/srand</a> - </p> -</div> |
