struct.JitterRng.html 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta name="generator" content="rustdoc">
  7. <meta name="description" content="API documentation for the Rust `JitterRng` struct in crate `rand`.">
  8. <meta name="keywords" content="rust, rustlang, rust-lang, JitterRng">
  9. <title>rand::jitter::JitterRng - Rust</title>
  10. <link rel="stylesheet" type="text/css" href="../../normalize.css">
  11. <link rel="stylesheet" type="text/css" href="../../rustdoc.css" id="mainThemeStyle">
  12. <link rel="stylesheet" type="text/css" href="../../dark.css">
  13. <link rel="stylesheet" type="text/css" href="../../main.css" id="themeStyle">
  14. <script src="../../storage.js"></script>
  15. <link rel="shortcut icon" href="https://www.rust-lang.org/favicon.ico">
  16. </head>
  17. <body class="rustdoc struct">
  18. <!--[if lte IE 8]>
  19. <div class="warning">
  20. This old browser is unsupported and will most likely display funky
  21. things.
  22. </div>
  23. <![endif]-->
  24. <nav class="sidebar">
  25. <div class="sidebar-menu">&#9776;</div>
  26. <a href='../../rand/index.html'><img src='https://www.rust-lang.org/logos/rust-logo-128x128-blk.png' alt='logo' width='100'></a>
  27. <p class='location'>Struct JitterRng</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#methods">Methods</a><div class="sidebar-links"><a href="#method.new">new</a><a href="#method.new_with_timer">new_with_timer</a><a href="#method.set_rounds">set_rounds</a><a href="#method.test_timer">test_timer</a><a href="#method.timer_stats">timer_stats</a></div><a class="sidebar-title" href="#implementations">Trait Implementations</a><div class="sidebar-links"><a href="#impl-Debug">Debug</a><a href="#impl-Rng">Rng</a></div></div><p class='location'><a href='../index.html'>rand</a>::<wbr><a href='index.html'>jitter</a></p><script>window.sidebarCurrent = {name: 'JitterRng', ty: 'struct', relpath: ''};</script><script defer src="sidebar-items.js"></script></div>
  28. </nav>
  29. <div class="theme-picker">
  30. <button id="theme-picker" aria-label="Pick another theme!">
  31. <img src="../../brush.svg" width="18" alt="Pick another theme!">
  32. </button>
  33. <div id="theme-choices"></div>
  34. </div>
  35. <script src="../../theme.js"></script>
  36. <nav class="sub">
  37. <form class="search-form js-only">
  38. <div class="search-container">
  39. <input class="search-input" name="search"
  40. autocomplete="off"
  41. placeholder="Click or press ‘S’ to search, ‘?’ for more options…"
  42. type="search">
  43. </div>
  44. </form>
  45. </nav>
  46. <section id='main' class="content">
  47. <h1 class='fqn'><span class='in-band'>Struct <a href='../index.html'>rand</a>::<wbr><a href='index.html'>jitter</a>::<wbr><a class="struct" href=''>JitterRng</a></span><span class='out-of-band'><span id='render-detail'>
  48. <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">
  49. [<span class='inner'>&#x2212;</span>]
  50. </a>
  51. </span><a class='srclink' href='../../src/rand/jitter.rs.html#51-66' title='goto source code'>[src]</a></span></h1>
  52. <pre class='rust struct'>pub struct JitterRng { /* fields omitted */ }</pre><div class='docblock'><p>A true random number generator based on jitter in the CPU execution time,
  53. and jitter in memory access time.</p>
  54. <p>This is a true random number generator, as opposed to pseudo-random
  55. generators. Random numbers generated by <code>JitterRng</code> can be seen as fresh
  56. entropy. A consequence is that is orders of magnitude slower than <code>OsRng</code>
  57. and PRNGs (about 10^3 .. 10^6 slower).</p>
  58. <p>There are very few situations where using this RNG is appropriate. Only very
  59. few applications require true entropy. A normal PRNG can be statistically
  60. indistinguishable, and a cryptographic PRNG should also be as impossible to
  61. predict.</p>
  62. <p>Use of <code>JitterRng</code> is recommended for initializing cryptographic PRNGs when
  63. <code>OsRng</code> is not available.</p>
  64. <p>This implementation is based on
  65. <a href="http://www.chronox.de/jent.html">Jitterentropy</a> version 2.1.0.</p>
  66. </div>
  67. <h2 id='methods' class='small-section-header'>
  68. Methods<a href='#methods' class='anchor'></a>
  69. </h2>
  70. <h3 id='impl' class='impl'><span class='in-band'><code>impl <a class="struct" href="../../rand/jitter/struct.JitterRng.html" title="struct rand::jitter::JitterRng">JitterRng</a></code><a href='#impl' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/rand/jitter.rs.html#122-663' title='goto source code'>[src]</a></span></h3>
  71. <div class='impl-items'><h4 id='method.new' class="method"><span id='new.v' class='invisible'><code>pub fn <a href='#method.new' class='fnname'>new</a>() -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="../../rand/jitter/struct.JitterRng.html" title="struct rand::jitter::JitterRng">JitterRng</a>, <a class="enum" href="../../rand/jitter/enum.TimerError.html" title="enum rand::jitter::TimerError">TimerError</a>&gt;</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/rand/jitter.rs.html#130-141' title='goto source code'>[src]</a></span></h4>
  72. <div class='docblock'><p>Create a new <code>JitterRng</code>.
  73. Makes use of <code>std::time</code> for a timer.</p>
  74. <p>During initialization CPU execution timing jitter is measured a few
  75. hundred times. If this does not pass basic quality tests, an error is
  76. returned. The test result is cached to make subsequent calls faster.</p>
  77. </div><h4 id='method.new_with_timer' class="method"><span id='new_with_timer.v' class='invisible'><code>pub fn <a href='#method.new_with_timer' class='fnname'>new_with_timer</a>(timer: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.fn.html">fn</a>() -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u64.html">u64</a>) -&gt; <a class="struct" href="../../rand/jitter/struct.JitterRng.html" title="struct rand::jitter::JitterRng">JitterRng</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/rand/jitter.rs.html#152-177' title='goto source code'>[src]</a></span></h4>
  78. <div class='docblock'><p>Create a new <code>JitterRng</code>.
  79. A custom timer can be supplied, making it possible to use <code>JitterRng</code> in
  80. <code>no_std</code> environments.</p>
  81. <p>The timer must have nanosecond precision.</p>
  82. <p>This method is more low-level than <code>new()</code>. It is the responsibility of
  83. the caller to run <code>test_timer</code> before using any numbers generated with
  84. <code>JitterRng</code>, and optionally call <code>set_rounds()</code>.</p>
  85. </div><h4 id='method.set_rounds' class="method"><span id='set_rounds.v' class='invisible'><code>pub fn <a href='#method.set_rounds' class='fnname'>set_rounds</a>(&amp;mut self, rounds: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>)</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/rand/jitter.rs.html#187-190' title='goto source code'>[src]</a></span></h4>
  86. <div class='docblock'><p>Configures how many rounds are used to generate each 64-bit value.
  87. This must be greater than zero, and has a big impact on performance
  88. and output quality.</p>
  89. <p><code>new_with_timer</code> conservatively uses 64 rounds, but often less rounds
  90. can be used. The <code>test_timer()</code> function returns the minimum number of
  91. rounds required for full strength (platform dependent), so one may use
  92. <code>rng.set_rounds(rng.test_timer()?);</code> or cache the value.</p>
  93. </div><h4 id='method.test_timer' class="method"><span id='test_timer.v' class='invisible'><code>pub fn <a href='#method.test_timer' class='fnname'>test_timer</a>(&amp;mut self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>, <a class="enum" href="../../rand/jitter/enum.TimerError.html" title="enum rand::jitter::TimerError">TimerError</a>&gt;</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/rand/jitter.rs.html#439-562' title='goto source code'>[src]</a></span></h4>
  94. <div class='docblock'><p>Basic quality tests on the timer, by measuring CPU timing jitter a few
  95. hundred times.</p>
  96. <p>If succesful, this will return the estimated number of rounds necessary
  97. to collect 64 bits of entropy. Otherwise a <code>TimerError</code> with the cause
  98. of the failure will be returned.</p>
  99. </div><h4 id='method.timer_stats' class="method"><span id='timer_stats.v' class='invisible'><code>pub fn <a href='#method.timer_stats' class='fnname'>timer_stats</a>(&amp;mut self, var_rounds: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i64.html">i64</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/rand/jitter.rs.html#656-662' title='goto source code'>[src]</a></span></h4>
  100. <div class='docblock'><p>Statistical test: return the timer delta of one normal run of the
  101. <code>JitterEntropy</code> entropy collector.</p>
  102. <p>Setting <code>var_rounds</code> to <code>true</code> will execute the memory access and the
  103. CPU jitter noice sources a variable amount of times (just like a real
  104. <code>JitterEntropy</code> round).</p>
  105. <p>Setting <code>var_rounds</code> to <code>false</code> will execute the noice sources the
  106. minimal number of times. This can be used to measure the minimum amount
  107. of entropy one round of entropy collector can collect in the worst case.</p>
  108. <h1 id="example" class="section-header"><a href="#example">Example</a></h1>
  109. <p>Use <code>timer_stats</code> to run the [NIST SP 800-90B Entropy Estimation Suite]
  110. (https://github.com/usnistgov/SP800-90B_EntropyAssessment).</p>
  111. <p>This is the recommended way to test the quality of <code>JitterRng</code>. It
  112. should be run before using the RNG on untested hardware, after changes
  113. that could effect how the code is optimised, and after major compiler
  114. compiler changes, like a new LLVM version.</p>
  115. <p>First generate two files <code>jitter_rng_var.bin</code> and <code>jitter_rng_var.min</code>.</p>
  116. <p>Execute <code>python noniid_main.py -v jitter_rng_var.bin 8</code>, and validate it
  117. with <code>restart.py -v jitter_rng_var.bin 8 &lt;min-entropy&gt;</code>.
  118. This number is the expected amount of entropy that is at least available
  119. for each round of the entropy collector. This number should be greater
  120. than the amount estimated with <code>64 / test_timer()</code>.</p>
  121. <p>Execute <code>python noniid_main.py -v -u 4 jitter_rng_var.bin 4</code>, and
  122. validate it with <code>restart.py -v -u 4 jitter_rng_var.bin 4 &lt;min-entropy&gt;</code>.
  123. This number is the expected amount of entropy that is available in the
  124. last 4 bits of the timer delta after running noice sources. Note that
  125. a value of 3.70 is the minimum estimated entropy for true randomness.</p>
  126. <p>Execute <code>python noniid_main.py -v -u 4 jitter_rng_var.bin 4</code>, and
  127. validate it with <code>restart.py -v -u 4 jitter_rng_var.bin 4 &lt;min-entropy&gt;</code>.
  128. This number is the expected amount of entropy that is available to the
  129. entropy collecter if both noice sources only run their minimal number of
  130. times. This measures the absolute worst-case, and gives a lower bound
  131. for the available entropy.</p>
  132. <pre class="rust rust-example-rendered">
  133. <span class="kw">use</span> <span class="ident">rand</span>::<span class="ident">JitterRng</span>;
  134. <span class="kw">fn</span> <span class="ident">get_nstime</span>() <span class="op">-&gt;</span> <span class="ident">u64</span> {
  135. <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">time</span>::{<span class="ident">SystemTime</span>, <span class="ident">UNIX_EPOCH</span>};
  136. <span class="kw">let</span> <span class="ident">dur</span> <span class="op">=</span> <span class="ident">SystemTime</span>::<span class="ident">now</span>().<span class="ident">duration_since</span>(<span class="ident">UNIX_EPOCH</span>).<span class="ident">unwrap</span>();
  137. <span class="comment">// The correct way to calculate the current time is</span>
  138. <span class="comment">// `dur.as_secs() * 1_000_000_000 + dur.subsec_nanos() as u64`</span>
  139. <span class="comment">// But this is faster, and the difference in terms of entropy is</span>
  140. <span class="comment">// negligible (log2(10^9) == 29.9).</span>
  141. <span class="ident">dur</span>.<span class="ident">as_secs</span>() <span class="op">&lt;&lt;</span> <span class="number">30</span> <span class="op">|</span> <span class="ident">dur</span>.<span class="ident">subsec_nanos</span>() <span class="kw">as</span> <span class="ident">u64</span>
  142. }
  143. <span class="comment">// Do not initialize with `JitterRng::new`, but with `new_with_timer`.</span>
  144. <span class="comment">// &#39;new&#39; always runst `test_timer`, and can therefore fail to</span>
  145. <span class="comment">// initialize. We want to be able to get the statistics even when the</span>
  146. <span class="comment">// timer test fails.</span>
  147. <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">rng</span> <span class="op">=</span> <span class="ident">JitterRng</span>::<span class="ident">new_with_timer</span>(<span class="ident">get_nstime</span>);
  148. <span class="comment">// 1_000_000 results are required for the NIST SP 800-90B Entropy</span>
  149. <span class="comment">// Estimation Suite</span>
  150. <span class="comment">// FIXME: this number is smaller here, otherwise the Doc-test is too slow</span>
  151. <span class="kw">const</span> <span class="ident">ROUNDS</span>: <span class="ident">usize</span> <span class="op">=</span> <span class="number">10_000</span>;
  152. <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">deltas_variable</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="ident">u8</span><span class="op">&gt;</span> <span class="op">=</span> <span class="ident">Vec</span>::<span class="ident">with_capacity</span>(<span class="ident">ROUNDS</span>);
  153. <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">deltas_minimal</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="ident">u8</span><span class="op">&gt;</span> <span class="op">=</span> <span class="ident">Vec</span>::<span class="ident">with_capacity</span>(<span class="ident">ROUNDS</span>);
  154. <span class="kw">for</span> _ <span class="kw">in</span> <span class="number">0</span>..<span class="ident">ROUNDS</span> {
  155. <span class="ident">deltas_variable</span>.<span class="ident">push</span>(<span class="ident">rng</span>.<span class="ident">timer_stats</span>(<span class="bool-val">true</span>) <span class="kw">as</span> <span class="ident">u8</span>);
  156. <span class="ident">deltas_minimal</span>.<span class="ident">push</span>(<span class="ident">rng</span>.<span class="ident">timer_stats</span>(<span class="bool-val">false</span>) <span class="kw">as</span> <span class="ident">u8</span>);
  157. }
  158. <span class="comment">// Write out after the statistics collection loop, to not disturb the</span>
  159. <span class="comment">// test results.</span>
  160. <span class="ident">File</span>::<span class="ident">create</span>(<span class="string">&quot;jitter_rng_var.bin&quot;</span>)<span class="question-mark">?</span>.<span class="ident">write</span>(<span class="kw-2">&amp;</span><span class="ident">deltas_variable</span>)<span class="question-mark">?</span>;
  161. <span class="ident">File</span>::<span class="ident">create</span>(<span class="string">&quot;jitter_rng_min.bin&quot;</span>)<span class="question-mark">?</span>.<span class="ident">write</span>(<span class="kw-2">&amp;</span><span class="ident">deltas_minimal</span>)<span class="question-mark">?</span>;</pre>
  162. </div></div>
  163. <h2 id='implementations' class='small-section-header'>
  164. Trait Implementations<a href='#implementations' class='anchor'></a>
  165. </h2>
  166. <h3 id='impl-Debug' class='impl'><span class='in-band'><code>impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a> for <a class="struct" href="../../rand/jitter/struct.JitterRng.html" title="struct rand::jitter::JitterRng">JitterRng</a></code><a href='#impl-Debug' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/rand/jitter.rs.html#69-73' title='goto source code'>[src]</a></span></h3>
  167. <div class='impl-items'><h4 id='method.fmt' class="method"><span id='fmt.v' class='invisible'><code>fn <a href='https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html#tymethod.fmt' class='fnname'>fmt</a>(&amp;self, f: &amp;mut <a class="struct" href="https://doc.rust-lang.org/nightly/core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a>) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/core/fmt/type.Result.html" title="type core::fmt::Result">Result</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/rand/jitter.rs.html#70-72' title='goto source code'>[src]</a></span></h4>
  168. <div class='docblock'><p>Formats the value using the given formatter. <a href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html#tymethod.fmt">Read more</a></p>
  169. </div></div><h3 id='impl-Rng' class='impl'><span class='in-band'><code>impl <a class="trait" href="../../rand/trait.Rng.html" title="trait rand::Rng">Rng</a> for <a class="struct" href="../../rand/jitter/struct.JitterRng.html" title="struct rand::jitter::JitterRng">JitterRng</a></code><a href='#impl-Rng' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/rand/jitter.rs.html#717-751' title='goto source code'>[src]</a></span></h3>
  170. <div class='impl-items'><h4 id='method.next_u32' class="method"><span id='next_u32.v' class='invisible'><code>fn <a href='../../rand/trait.Rng.html#tymethod.next_u32' class='fnname'>next_u32</a>(&amp;mut self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/rand/jitter.rs.html#718-727' title='goto source code'>[src]</a></span></h4>
  171. <div class='docblock'><p>Return the next random u32. <a href="../../rand/trait.Rng.html#tymethod.next_u32">Read more</a></p>
  172. </div><h4 id='method.next_u64' class="method"><span id='next_u64.v' class='invisible'><code>fn <a href='../../rand/trait.Rng.html#method.next_u64' class='fnname'>next_u64</a>(&amp;mut self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u64.html">u64</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/rand/jitter.rs.html#729-731' title='goto source code'>[src]</a></span></h4>
  173. <div class='docblock'><p>Return the next random u64. <a href="../../rand/trait.Rng.html#method.next_u64">Read more</a></p>
  174. </div><h4 id='method.fill_bytes' class="method"><span id='fill_bytes.v' class='invisible'><code>fn <a href='../../rand/trait.Rng.html#method.fill_bytes' class='fnname'>fill_bytes</a>(&amp;mut self, dest: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&amp;mut [</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>)</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/rand/jitter.rs.html#733-750' title='goto source code'>[src]</a></span></h4>
  175. <div class='docblock'><p>Fill <code>dest</code> with random data. <a href="../../rand/trait.Rng.html#method.fill_bytes">Read more</a></p>
  176. </div><h4 id='method.next_f32' class="method"><span id='next_f32.v' class='invisible'><code>fn <a href='../../rand/trait.Rng.html#method.next_f32' class='fnname'>next_f32</a>(&amp;mut self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.f32.html">f32</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/rand/lib.rs.html#383-389' title='goto source code'>[src]</a></span></h4>
  177. <div class='docblock'><p>Return the next random f32 selected from the half-open interval <code>[0, 1)</code>. <a href="../../rand/trait.Rng.html#method.next_f32">Read more</a></p>
  178. </div><h4 id='method.next_f64' class="method"><span id='next_f64.v' class='invisible'><code>fn <a href='../../rand/trait.Rng.html#method.next_f64' class='fnname'>next_f64</a>(&amp;mut self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.f64.html">f64</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/rand/lib.rs.html#401-407' title='goto source code'>[src]</a></span></h4>
  179. <div class='docblock'><p>Return the next random f64 selected from the half-open interval <code>[0, 1)</code>. <a href="../../rand/trait.Rng.html#method.next_f64">Read more</a></p>
  180. </div><h4 id='method.gen' class="method"><span id='gen.v' class='invisible'><code>fn <a href='../../rand/trait.Rng.html#method.gen' class='fnname'>gen</a>&lt;T:&nbsp;<a class="trait" href="../../rand/trait.Rand.html" title="trait rand::Rand">Rand</a>&gt;(&amp;mut self) -&gt; T <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,&nbsp;</span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/rand/lib.rs.html#473-475' title='goto source code'>[src]</a></span></h4>
  181. <div class='docblock'><p>Return a random value of a <code>Rand</code> type. <a href="../../rand/trait.Rng.html#method.gen">Read more</a></p>
  182. </div><h4 id='method.gen_iter' class="method"><div class="important-traits"><div class='tooltip'>ⓘ<span class='tooltiptext'>Important traits for <a class="struct" href="../../rand/struct.Generator.html" title="struct rand::Generator">Generator</a>&lt;'a, T, R&gt;</span></div><div class="content hidden"><h3 class="important">Important traits for <a class="struct" href="../../rand/struct.Generator.html" title="struct rand::Generator">Generator</a>&lt;'a, T, R&gt;</h3><code class="content"><span class="where fmt-newline">impl&lt;'a, T:&nbsp;<a class="trait" href="../../rand/trait.Rand.html" title="trait rand::Rand">Rand</a>, R:&nbsp;<a class="trait" href="../../rand/trait.Rng.html" title="trait rand::Rng">Rng</a>&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/iterator/trait.Iterator.html" title="trait core::iter::iterator::Iterator">Iterator</a> for <a class="struct" href="../../rand/struct.Generator.html" title="struct rand::Generator">Generator</a>&lt;'a, T, R&gt;</span><span class="where fmt-newline"> type <a href='https://doc.rust-lang.org/nightly/core/iter/iterator/trait.Iterator.html#associatedtype.Item' class="type">Item</a> = T;</span></code></div></div><span id='gen_iter.v' class='invisible'><code>fn <a href='../../rand/trait.Rng.html#method.gen_iter' class='fnname'>gen_iter</a>&lt;'a, T:&nbsp;<a class="trait" href="../../rand/trait.Rand.html" title="trait rand::Rand">Rand</a>&gt;(&amp;'a mut self) -&gt; <a class="struct" href="../../rand/struct.Generator.html" title="struct rand::Generator">Generator</a>&lt;'a, T, Self&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,&nbsp;</span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/rand/lib.rs.html#491-493' title='goto source code'>[src]</a></span></h4>
  183. <div class='docblock'><p>Return an iterator that will yield an infinite number of randomly generated items. <a href="../../rand/trait.Rng.html#method.gen_iter">Read more</a></p>
  184. </div><h4 id='method.gen_range' class="method"><span id='gen_range.v' class='invisible'><code>fn <a href='../../rand/trait.Rng.html#method.gen_range' class='fnname'>gen_range</a>&lt;T:&nbsp;<a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a> + <a class="trait" href="../../rand/distributions/range/trait.SampleRange.html" title="trait rand::distributions::range::SampleRange">SampleRange</a>&gt;(&amp;mut self, low: T, high: T) -&gt; T <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,&nbsp;</span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/rand/lib.rs.html#518-521' title='goto source code'>[src]</a></span></h4>
  185. <div class='docblock'><p>Generate a random value in the range [<code>low</code>, <code>high</code>). <a href="../../rand/trait.Rng.html#method.gen_range">Read more</a></p>
  186. </div><h4 id='method.gen_weighted_bool' class="method"><span id='gen_weighted_bool.v' class='invisible'><code>fn <a href='../../rand/trait.Rng.html#method.gen_weighted_bool' class='fnname'>gen_weighted_bool</a>(&amp;mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a> <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,&nbsp;</span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/rand/lib.rs.html#533-535' title='goto source code'>[src]</a></span></h4>
  187. <div class='docblock'><p>Return a bool with a 1 in n chance of true <a href="../../rand/trait.Rng.html#method.gen_weighted_bool">Read more</a></p>
  188. </div><h4 id='method.gen_ascii_chars' class="method"><div class="important-traits"><div class='tooltip'>ⓘ<span class='tooltiptext'>Important traits for <a class="struct" href="../../rand/struct.AsciiGenerator.html" title="struct rand::AsciiGenerator">AsciiGenerator</a>&lt;'a, R&gt;</span></div><div class="content hidden"><h3 class="important">Important traits for <a class="struct" href="../../rand/struct.AsciiGenerator.html" title="struct rand::AsciiGenerator">AsciiGenerator</a>&lt;'a, R&gt;</h3><code class="content"><span class="where fmt-newline">impl&lt;'a, R:&nbsp;<a class="trait" href="../../rand/trait.Rng.html" title="trait rand::Rng">Rng</a>&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/iterator/trait.Iterator.html" title="trait core::iter::iterator::Iterator">Iterator</a> for <a class="struct" href="../../rand/struct.AsciiGenerator.html" title="struct rand::AsciiGenerator">AsciiGenerator</a>&lt;'a, R&gt;</span><span class="where fmt-newline"> type <a href='https://doc.rust-lang.org/nightly/core/iter/iterator/trait.Iterator.html#associatedtype.Item' class="type">Item</a> = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.char.html">char</a>;</span></code></div></div><span id='gen_ascii_chars.v' class='invisible'><code>fn <a href='../../rand/trait.Rng.html#method.gen_ascii_chars' class='fnname'>gen_ascii_chars</a>&lt;'a&gt;(&amp;'a mut self) -&gt; <a class="struct" href="../../rand/struct.AsciiGenerator.html" title="struct rand::AsciiGenerator">AsciiGenerator</a>&lt;'a, Self&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,&nbsp;</span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/rand/lib.rs.html#547-549' title='goto source code'>[src]</a></span></h4>
  189. <div class='docblock'><p>Return an iterator of random characters from the set A-Z,a-z,0-9. <a href="../../rand/trait.Rng.html#method.gen_ascii_chars">Read more</a></p>
  190. </div><h4 id='method.choose' class="method"><span id='choose.v' class='invisible'><code>fn <a href='../../rand/trait.Rng.html#method.choose' class='fnname'>choose</a>&lt;'a, T&gt;(&amp;mut self, values: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&amp;'a [T]</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;'a </a>T&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,&nbsp;</span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/rand/lib.rs.html#565-571' title='goto source code'>[src]</a></span></h4>
  191. <div class='docblock'><p>Return a random element from <code>values</code>. <a href="../../rand/trait.Rng.html#method.choose">Read more</a></p>
  192. </div><h4 id='method.choose_mut' class="method"><span id='choose_mut.v' class='invisible'><code>fn <a href='../../rand/trait.Rng.html#method.choose_mut' class='fnname'>choose_mut</a>&lt;'a, T&gt;(&amp;mut self, values: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&amp;'a mut [T]</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;'a mut </a>T&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,&nbsp;</span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/rand/lib.rs.html#576-583' title='goto source code'>[src]</a></span></h4>
  193. <div class='docblock'><p>Return a mutable pointer to a random element from <code>values</code>. <a href="../../rand/trait.Rng.html#method.choose_mut">Read more</a></p>
  194. </div><h4 id='method.shuffle' class="method"><span id='shuffle.v' class='invisible'><code>fn <a href='../../rand/trait.Rng.html#method.shuffle' class='fnname'>shuffle</a>&lt;T&gt;(&amp;mut self, values: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&amp;mut [T]</a>) <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,&nbsp;</span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/rand/lib.rs.html#602-610' title='goto source code'>[src]</a></span></h4>
  195. <div class='docblock'><p>Shuffle a mutable slice in place. <a href="../../rand/trait.Rng.html#method.shuffle">Read more</a></p>
  196. </div></div></section>
  197. <section id='search' class="content hidden"></section>
  198. <section class="footer"></section>
  199. <aside id="help" class="hidden">
  200. <div>
  201. <h1 class="hidden">Help</h1>
  202. <div class="shortcuts">
  203. <h2>Keyboard Shortcuts</h2>
  204. <dl>
  205. <dt><kbd>?</kbd></dt>
  206. <dd>Show this help dialog</dd>
  207. <dt><kbd>S</kbd></dt>
  208. <dd>Focus the search field</dd>
  209. <dt><kbd>↑</kbd></dt>
  210. <dd>Move up in search results</dd>
  211. <dt><kbd>↓</kbd></dt>
  212. <dd>Move down in search results</dd>
  213. <dt><kbd>↹</kbd></dt>
  214. <dd>Switch tab</dd>
  215. <dt><kbd>&#9166;</kbd></dt>
  216. <dd>Go to active search result</dd>
  217. <dt><kbd>+</kbd></dt>
  218. <dd>Expand all sections</dd>
  219. <dt><kbd>-</kbd></dt>
  220. <dd>Collapse all sections</dd>
  221. </dl>
  222. </div>
  223. <div class="infos">
  224. <h2>Search Tricks</h2>
  225. <p>
  226. Prefix searches with a type followed by a colon (e.g.
  227. <code>fn:</code>) to restrict the search to a given type.
  228. </p>
  229. <p>
  230. Accepted types are: <code>fn</code>, <code>mod</code>,
  231. <code>struct</code>, <code>enum</code>,
  232. <code>trait</code>, <code>type</code>, <code>macro</code>,
  233. and <code>const</code>.
  234. </p>
  235. <p>
  236. Search functions by type signature (e.g.
  237. <code>vec -> usize</code> or <code>* -> vec</code>)
  238. </p>
  239. </div>
  240. </div>
  241. </aside>
  242. <script>
  243. window.rootPath = "../../";
  244. window.currentCrate = "rand";
  245. </script>
  246. <script src="../../main.js"></script>
  247. <script defer src="../../search-index.js"></script>
  248. </body>
  249. </html>