trait.Rng.html 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="API documentation for the Rust `Rng` trait in crate `rand`."><meta name="keywords" content="rust, rustlang, rust-lang, Rng"><title>rand::Rng - Rust</title><link rel="stylesheet" type="text/css" href="../normalize.css"><link rel="stylesheet" type="text/css" href="../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../dark.css"><link rel="stylesheet" type="text/css" href="../light.css" id="themeStyle"><script src="../storage.js"></script><link rel="shortcut icon" href="https://www.rust-lang.org/favicon.ico"></head><body class="rustdoc trait"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu">&#9776;</div><a href='../rand/index.html'><img src='https://www.rust-lang.org/logos/rust-logo-128x128-blk.png' alt='logo' width='100'></a><p class='location'>Trait Rng</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#provided-methods">Provided Methods</a><div class="sidebar-links"><a href="#method.gen">gen</a><a href="#method.gen_range">gen_range</a><a href="#method.sample">sample</a><a href="#method.sample_iter">sample_iter</a><a href="#method.fill">fill</a><a href="#method.try_fill">try_fill</a><a href="#method.gen_bool">gen_bool</a><a href="#method.choose">choose</a><a href="#method.choose_mut">choose_mut</a><a href="#method.shuffle">shuffle</a><a href="#method.gen_iter">gen_iter</a><a href="#method.gen_weighted_bool">gen_weighted_bool</a><a href="#method.gen_ascii_chars">gen_ascii_chars</a></div><a class="sidebar-title" href="#implementors">Implementors</a></div><p class='location'><a href='index.html'>rand</a></p><script>window.sidebarCurrent = {name: 'Rng', ty: 'trait', relpath: ''};</script><script defer src="sidebar-items.js"></script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!"><img src="../brush.svg" width="18" alt="Pick another theme!"></button><div id="theme-choices"></div></div><script src="../theme.js"></script><nav class="sub"><form class="search-form js-only"><div class="search-container"><input class="search-input" name="search" autocomplete="off" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><a id="settings-menu" href="../settings.html"><img src="../wheel.svg" width="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class='fqn'><span class='in-band'>Trait <a href='index.html'>rand</a>::<wbr><a class="trait" href=''>Rng</a></span><span class='out-of-band'><span id='render-detail'><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class='inner'>&#x2212;</span>]</a></span><a class='srclink' href='../src/rand/lib.rs.html#413-723' title='goto source code'>[src]</a></span></h1><div class="docblock type-decl"><pre class='rust trait'>pub trait Rng: <a class="trait" href="../rand/trait.RngCore.html" title="trait rand::RngCore">RngCore</a> {
  2. fn <a href='#method.gen' class='fnname'>gen</a>&lt;T&gt;(&amp;mut self) -&gt; T<br>&nbsp;&nbsp;&nbsp; <span class="where">where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class="struct" href="../rand/distributions/struct.Standard.html" title="struct rand::distributions::Standard">Standard</a>: <a class="trait" href="../rand/distributions/trait.Distribution.html" title="trait rand::distributions::Distribution">Distribution</a>&lt;T&gt;</span>,
  3. { ... }
  4. <div class='item-spacer'></div> fn <a href='#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/uniform/trait.SampleUniform.html" title="trait rand::distributions::uniform::SampleUniform">SampleUniform</a>&gt;(&amp;mut self, low: T, high: T) -&gt; T { ... }
  5. <div class='item-spacer'></div> fn <a href='#method.sample' class='fnname'>sample</a>&lt;T, D:&nbsp;<a class="trait" href="../rand/distributions/trait.Distribution.html" title="trait rand::distributions::Distribution">Distribution</a>&lt;T&gt;&gt;(&amp;mut self, distr: D) -&gt; T { ... }
  6. <div class='item-spacer'></div> fn <a href='#method.sample_iter' class='fnname'>sample_iter</a>&lt;'a, T, D:&nbsp;<a class="trait" href="../rand/distributions/trait.Distribution.html" title="trait rand::distributions::Distribution">Distribution</a>&lt;T&gt;&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;'a mut self, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;distr: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;'a </a>D<br>&nbsp;&nbsp;&nbsp;&nbsp;) -&gt; <a class="struct" href="../rand/distributions/struct.DistIter.html" title="struct rand::distributions::DistIter">DistIter</a>&lt;'a, D, Self, T&gt;<br>&nbsp;&nbsp;&nbsp; <span class="where">where<br>&nbsp;&nbsp;&nbsp;&nbsp;&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></span>,
  7. { ... }
  8. <div class='item-spacer'></div> fn <a href='#method.fill' class='fnname'>fill</a>&lt;T:&nbsp;<a class="trait" href="../rand/trait.AsByteSliceMut.html" title="trait rand::AsByteSliceMut">AsByteSliceMut</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>&gt;(&amp;mut self, dest: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;mut </a>T) { ... }
  9. <div class='item-spacer'></div> fn <a href='#method.try_fill' class='fnname'>try_fill</a>&lt;T:&nbsp;<a class="trait" href="../rand/trait.AsByteSliceMut.html" title="trait rand::AsByteSliceMut">AsByteSliceMut</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;mut self, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;mut </a>T<br>&nbsp;&nbsp;&nbsp;&nbsp;) -&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.unit.html">()</a>, <a class="struct" href="../rand/struct.Error.html" title="struct rand::Error">Error</a>&gt; { ... }
  10. <div class='item-spacer'></div> fn <a href='#method.gen_bool' class='fnname'>gen_bool</a>(&amp;mut self, p: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.f64.html">f64</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a> { ... }
  11. <div class='item-spacer'></div> fn <a href='#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; { ... }
  12. <div class='item-spacer'></div> fn <a href='#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; { ... }
  13. <div class='item-spacer'></div> fn <a href='#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>) { ... }
  14. <div class='item-spacer'></div> fn <a href='#method.gen_iter' class='fnname'>gen_iter</a>&lt;T&gt;(&amp;mut self) -&gt; <a class="struct" href="../rand/struct.Generator.html" title="struct rand::Generator">Generator</a>&lt;T, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;mut </a>Self&gt;<br>&nbsp;&nbsp;&nbsp; <span class="where">where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class="struct" href="../rand/distributions/struct.Standard.html" title="struct rand::distributions::Standard">Standard</a>: <a class="trait" href="../rand/distributions/trait.Distribution.html" title="trait rand::distributions::Distribution">Distribution</a>&lt;T&gt;</span>,
  15. { ... }
  16. <div class='item-spacer'></div> fn <a href='#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> { ... }
  17. <div class='item-spacer'></div> fn <a href='#method.gen_ascii_chars' class='fnname'>gen_ascii_chars</a>(&amp;mut self) -&gt; <a class="struct" href="../rand/struct.AsciiGenerator.html" title="struct rand::AsciiGenerator">AsciiGenerator</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;mut </a>Self&gt; { ... }
  18. }</pre></div><div class='docblock'><p>An automatically-implemented extension trait on <a href="trait.RngCore.html"><code>RngCore</code></a> providing high-level
  19. generic methods for sampling values and other convenience methods.</p>
  20. <p>This is the primary trait to use when generating random values.</p>
  21. <h1 id="generic-usage" class="section-header"><a href="#generic-usage">Generic usage</a></h1>
  22. <p>The basic pattern is <code>fn foo&lt;R: Rng + ?Sized&gt;(rng: &amp;mut R)</code>. Some
  23. things are worth noting here:</p>
  24. <ul>
  25. <li>Since <code>Rng: RngCore</code> and every <code>RngCore</code> implements <code>Rng</code>, it makes no
  26. difference whether we use <code>R: Rng</code> or <code>R: RngCore</code>.</li>
  27. <li>The <code>+ ?Sized</code> un-bounding allows functions to be called directly on
  28. type-erased references; i.e. <code>foo(r)</code> where <code>r: &amp;mut RngCore</code>. Without
  29. this it would be necessary to write <code>foo(&amp;mut r)</code>.</li>
  30. </ul>
  31. <p>An alternative pattern is possible: <code>fn foo&lt;R: Rng&gt;(rng: R)</code>. This has some
  32. trade-offs. It allows the argument to be consumed directly without a <code>&amp;mut</code>
  33. (which is how <code>from_rng(thread_rng())</code> works); also it still works directly
  34. on references (including type-erased references). Unfortunately within the
  35. function <code>foo</code> it is not known whether <code>rng</code> is a reference type or not,
  36. hence many uses of <code>rng</code> require an extra reference, either explicitly
  37. (<code>distr.sample(&amp;mut rng)</code>) or implicitly (<code>rng.gen()</code>); one may hope the
  38. optimiser can remove redundant references later.</p>
  39. <p>Example:</p>
  40. <pre class="rust rust-example-rendered">
  41. <span class="kw">use</span> <span class="ident">rand</span>::<span class="ident">Rng</span>;
  42. <span class="kw">fn</span> <span class="ident">foo</span><span class="op">&lt;</span><span class="ident">R</span>: <span class="ident">Rng</span> <span class="op">+</span> <span class="question-mark">?</span><span class="ident">Sized</span><span class="op">&gt;</span>(<span class="ident">rng</span>: <span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="ident">R</span>) <span class="op">-&gt;</span> <span class="ident">f32</span> {
  43. <span class="ident">rng</span>.<span class="ident">gen</span>()
  44. }
  45. </pre>
  46. </div>
  47. <h2 id='provided-methods' class='small-section-header'>
  48. Provided Methods<a href='#provided-methods' class='anchor'></a>
  49. </h2>
  50. <div class='methods'>
  51. <h3 id='method.gen' class='method'><span id='gen.v' class='invisible'><code>fn <a href='#method.gen' class='fnname'>gen</a>&lt;T&gt;(&amp;mut self) -&gt; T <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;<a class="struct" href="../rand/distributions/struct.Standard.html" title="struct rand::distributions::Standard">Standard</a>: <a class="trait" href="../rand/distributions/trait.Distribution.html" title="trait rand::distributions::Distribution">Distribution</a>&lt;T&gt;,&nbsp;</span></code></span></h3><div class='docblock'><p>Return a random value supporting the <a href="distributions/struct.Standard.html"><code>Standard</code></a> distribution.</p>
  52. <h1 id="example" class="section-header"><a href="#example">Example</a></h1>
  53. <pre class="rust rust-example-rendered">
  54. <span class="kw">use</span> <span class="ident">rand</span>::{<span class="ident">thread_rng</span>, <span class="ident">Rng</span>};
  55. <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">rng</span> <span class="op">=</span> <span class="ident">thread_rng</span>();
  56. <span class="kw">let</span> <span class="ident">x</span>: <span class="ident">u32</span> <span class="op">=</span> <span class="ident">rng</span>.<span class="ident">gen</span>();
  57. <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;{}&quot;</span>, <span class="ident">x</span>);
  58. <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;{:?}&quot;</span>, <span class="ident">rng</span>.<span class="ident">gen</span>::<span class="op">&lt;</span>(<span class="ident">f64</span>, <span class="ident">bool</span>)<span class="op">&gt;</span>());</pre>
  59. </div><h3 id='method.gen_range' class='method'><span id='gen_range.v' class='invisible'><code>fn <a href='#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/uniform/trait.SampleUniform.html" title="trait rand::distributions::uniform::SampleUniform">SampleUniform</a>&gt;(&amp;mut self, low: T, high: T) -&gt; T</code></span></h3><div class='docblock'><p>Generate a random value in the range [<code>low</code>, <code>high</code>), i.e. inclusive of
  60. <code>low</code> and exclusive of <code>high</code>.</p>
  61. <p>This function is optimised for the case that only a single sample is
  62. made from the given range. See also the <a href="distributions/uniform/struct.Uniform.html"><code>Uniform</code></a> distribution
  63. type which may be faster if sampling from the same range repeatedly.</p>
  64. <h1 id="panics" class="section-header"><a href="#panics">Panics</a></h1>
  65. <p>Panics if <code>low &gt;= high</code>.</p>
  66. <h1 id="example-1" class="section-header"><a href="#example-1">Example</a></h1>
  67. <pre class="rust rust-example-rendered">
  68. <span class="kw">use</span> <span class="ident">rand</span>::{<span class="ident">thread_rng</span>, <span class="ident">Rng</span>};
  69. <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">rng</span> <span class="op">=</span> <span class="ident">thread_rng</span>();
  70. <span class="kw">let</span> <span class="ident">n</span>: <span class="ident">u32</span> <span class="op">=</span> <span class="ident">rng</span>.<span class="ident">gen_range</span>(<span class="number">0</span>, <span class="number">10</span>);
  71. <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;{}&quot;</span>, <span class="ident">n</span>);
  72. <span class="kw">let</span> <span class="ident">m</span>: <span class="ident">f64</span> <span class="op">=</span> <span class="ident">rng</span>.<span class="ident">gen_range</span>(<span class="op">-</span><span class="number">40.0f64</span>, <span class="number">1.3e5f64</span>);
  73. <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;{}&quot;</span>, <span class="ident">m</span>);</pre>
  74. </div><h3 id='method.sample' class='method'><span id='sample.v' class='invisible'><code>fn <a href='#method.sample' class='fnname'>sample</a>&lt;T, D:&nbsp;<a class="trait" href="../rand/distributions/trait.Distribution.html" title="trait rand::distributions::Distribution">Distribution</a>&lt;T&gt;&gt;(&amp;mut self, distr: D) -&gt; T</code></span></h3><div class='docblock'><p>Sample a new value, using the given distribution.</p>
  75. <h3 id="example-2" class="section-header"><a href="#example-2">Example</a></h3>
  76. <pre class="rust rust-example-rendered">
  77. <span class="kw">use</span> <span class="ident">rand</span>::{<span class="ident">thread_rng</span>, <span class="ident">Rng</span>};
  78. <span class="kw">use</span> <span class="ident">rand</span>::<span class="ident">distributions</span>::<span class="ident">Uniform</span>;
  79. <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">rng</span> <span class="op">=</span> <span class="ident">thread_rng</span>();
  80. <span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="ident">rng</span>.<span class="ident">sample</span>(<span class="ident">Uniform</span>::<span class="ident">new</span>(<span class="number">10u32</span>, <span class="number">15</span>));
  81. <span class="comment">// Type annotation requires two types, the type and distribution; the</span>
  82. <span class="comment">// distribution can be inferred.</span>
  83. <span class="kw">let</span> <span class="ident">y</span> <span class="op">=</span> <span class="ident">rng</span>.<span class="ident">sample</span>::<span class="op">&lt;</span><span class="ident">u16</span>, <span class="kw">_</span><span class="op">&gt;</span>(<span class="ident">Uniform</span>::<span class="ident">new</span>(<span class="number">10</span>, <span class="number">15</span>));</pre>
  84. </div><div class="important-traits"><div class='tooltip'>ⓘ<span class='tooltiptext'>Important traits for <a class="struct" href="../rand/distributions/struct.DistIter.html" title="struct rand::distributions::DistIter">DistIter</a>&lt;'a, D, R, T&gt;</span></div><div class="content hidden"><h3 class="important">Important traits for <a class="struct" href="../rand/distributions/struct.DistIter.html" title="struct rand::distributions::DistIter">DistIter</a>&lt;'a, D, R, T&gt;</h3><code class="content"><span class="where fmt-newline">impl&lt;'a, D, R, T&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/distributions/struct.DistIter.html" title="struct rand::distributions::DistIter">DistIter</a>&lt;'a, D, R, T&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;D: <a class="trait" href="../rand/distributions/trait.Distribution.html" title="trait rand::distributions::Distribution">Distribution</a>&lt;T&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;R: <a class="trait" href="../rand/trait.Rng.html" title="trait rand::Rng">Rng</a> + 'a,&nbsp;</span></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><h3 id='method.sample_iter' class='method'><span id='sample_iter.v' class='invisible'><code>fn <a href='#method.sample_iter' class='fnname'>sample_iter</a>&lt;'a, T, D:&nbsp;<a class="trait" href="../rand/distributions/trait.Distribution.html" title="trait rand::distributions::Distribution">Distribution</a>&lt;T&gt;&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;'a mut self, <br>&nbsp;&nbsp;&nbsp;&nbsp;distr: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;'a </a>D<br>) -&gt; <a class="struct" href="../rand/distributions/struct.DistIter.html" title="struct rand::distributions::DistIter">DistIter</a>&lt;'a, D, Self, 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></h3><div class='docblock'><p>Create an iterator that generates values using the given distribution.</p>
  85. <h1 id="example-3" class="section-header"><a href="#example-3">Example</a></h1>
  86. <pre class="rust rust-example-rendered">
  87. <span class="kw">use</span> <span class="ident">rand</span>::{<span class="ident">thread_rng</span>, <span class="ident">Rng</span>};
  88. <span class="kw">use</span> <span class="ident">rand</span>::<span class="ident">distributions</span>::{<span class="ident">Alphanumeric</span>, <span class="ident">Uniform</span>, <span class="ident">Standard</span>};
  89. <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">rng</span> <span class="op">=</span> <span class="ident">thread_rng</span>();
  90. <span class="comment">// Vec of 16 x f32:</span>
  91. <span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="ident">f32</span><span class="op">&gt;</span> <span class="op">=</span> <span class="ident">thread_rng</span>().<span class="ident">sample_iter</span>(<span class="kw-2">&amp;</span><span class="ident">Standard</span>).<span class="ident">take</span>(<span class="number">16</span>).<span class="ident">collect</span>();
  92. <span class="comment">// String:</span>
  93. <span class="kw">let</span> <span class="ident">s</span>: <span class="ident">String</span> <span class="op">=</span> <span class="ident">rng</span>.<span class="ident">sample_iter</span>(<span class="kw-2">&amp;</span><span class="ident">Alphanumeric</span>).<span class="ident">take</span>(<span class="number">7</span>).<span class="ident">collect</span>();
  94. <span class="comment">// Combined values</span>
  95. <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;{:?}&quot;</span>, <span class="ident">thread_rng</span>().<span class="ident">sample_iter</span>(<span class="kw-2">&amp;</span><span class="ident">Standard</span>).<span class="ident">take</span>(<span class="number">5</span>)
  96. .<span class="ident">collect</span>::<span class="op">&lt;</span><span class="ident">Vec</span><span class="op">&lt;</span>(<span class="ident">f64</span>, <span class="ident">bool</span>)<span class="op">&gt;&gt;</span>());
  97. <span class="comment">// Dice-rolling:</span>
  98. <span class="kw">let</span> <span class="ident">die_range</span> <span class="op">=</span> <span class="ident">Uniform</span>::<span class="ident">new_inclusive</span>(<span class="number">1</span>, <span class="number">6</span>);
  99. <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">roll_die</span> <span class="op">=</span> <span class="ident">rng</span>.<span class="ident">sample_iter</span>(<span class="kw-2">&amp;</span><span class="ident">die_range</span>);
  100. <span class="kw">while</span> <span class="ident">roll_die</span>.<span class="ident">next</span>().<span class="ident">unwrap</span>() <span class="op">!=</span> <span class="number">6</span> {
  101. <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;Not a 6; rolling again!&quot;</span>);
  102. }</pre>
  103. </div><h3 id='method.fill' class='method'><span id='fill.v' class='invisible'><code>fn <a href='#method.fill' class='fnname'>fill</a>&lt;T:&nbsp;<a class="trait" href="../rand/trait.AsByteSliceMut.html" title="trait rand::AsByteSliceMut">AsByteSliceMut</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>&gt;(&amp;mut self, dest: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;mut </a>T)</code></span></h3><div class='docblock'><p>Fill <code>dest</code> entirely with random bytes (uniform value distribution),
  104. where <code>dest</code> is any type supporting <a href="trait.AsByteSliceMut.html"><code>AsByteSliceMut</code></a>, namely slices
  105. and arrays over primitive integer types (<code>i8</code>, <code>i16</code>, <code>u32</code>, etc.).</p>
  106. <p>On big-endian platforms this performs byte-swapping to ensure
  107. portability of results from reproducible generators.</p>
  108. <p>This uses <a href="trait.RngCore.html#method.fill_bytes"><code>fill_bytes</code></a> internally which may handle some RNG errors
  109. implicitly (e.g. waiting if the OS generator is not ready), but panics
  110. on other errors. See also <a href="trait.Rng.html#method.try_fill"><code>try_fill</code></a> which returns errors.</p>
  111. <h1 id="example-4" class="section-header"><a href="#example-4">Example</a></h1>
  112. <pre class="rust rust-example-rendered">
  113. <span class="kw">use</span> <span class="ident">rand</span>::{<span class="ident">thread_rng</span>, <span class="ident">Rng</span>};
  114. <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">arr</span> <span class="op">=</span> [<span class="number">0i8</span>; <span class="number">20</span>];
  115. <span class="ident">thread_rng</span>().<span class="ident">fill</span>(<span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="ident">arr</span>[..]);</pre>
  116. </div><h3 id='method.try_fill' class='method'><span id='try_fill.v' class='invisible'><code>fn <a href='#method.try_fill' class='fnname'>try_fill</a>&lt;T:&nbsp;<a class="trait" href="../rand/trait.AsByteSliceMut.html" title="trait rand::AsByteSliceMut">AsByteSliceMut</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;mut self, <br>&nbsp;&nbsp;&nbsp;&nbsp;dest: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;mut </a>T<br>) -&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.unit.html">()</a>, <a class="struct" href="../rand/struct.Error.html" title="struct rand::Error">Error</a>&gt;</code></span></h3><div class='docblock'><p>Fill <code>dest</code> entirely with random bytes (uniform value distribution),
  117. where <code>dest</code> is any type supporting <a href="trait.AsByteSliceMut.html"><code>AsByteSliceMut</code></a>, namely slices
  118. and arrays over primitive integer types (<code>i8</code>, <code>i16</code>, <code>u32</code>, etc.).</p>
  119. <p>On big-endian platforms this performs byte-swapping to ensure
  120. portability of results from reproducible generators.</p>
  121. <p>This uses <a href="trait.RngCore.html#method.try_fill_bytes"><code>try_fill_bytes</code></a> internally and forwards all RNG errors. In
  122. some cases errors may be resolvable; see <a href="enum.ErrorKind.html"><code>ErrorKind</code></a> and
  123. documentation for the RNG in use. If you do not plan to handle these
  124. errors you may prefer to use <a href="trait.Rng.html#method.fill"><code>fill</code></a>.</p>
  125. <h1 id="example-5" class="section-header"><a href="#example-5">Example</a></h1>
  126. <pre class="rust rust-example-rendered">
  127. <span class="kw">use</span> <span class="ident">rand</span>::{<span class="ident">thread_rng</span>, <span class="ident">Rng</span>};
  128. <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">arr</span> <span class="op">=</span> [<span class="number">0u64</span>; <span class="number">4</span>];
  129. <span class="ident">thread_rng</span>().<span class="ident">try_fill</span>(<span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="ident">arr</span>[..])<span class="question-mark">?</span>;
  130. </pre>
  131. </div><h3 id='method.gen_bool' class='method'><span id='gen_bool.v' class='invisible'><code>fn <a href='#method.gen_bool' class='fnname'>gen_bool</a>(&amp;mut self, p: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.f64.html">f64</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code></span></h3><div class='docblock'><p>Return a bool with a probability <code>p</code> of being true.</p>
  132. <p>This is a wrapper around <a href="distributions/bernoulli/struct.Bernoulli.html"><code>distributions::Bernoulli</code></a>.</p>
  133. <h1 id="example-6" class="section-header"><a href="#example-6">Example</a></h1>
  134. <pre class="rust rust-example-rendered">
  135. <span class="kw">use</span> <span class="ident">rand</span>::{<span class="ident">thread_rng</span>, <span class="ident">Rng</span>};
  136. <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">rng</span> <span class="op">=</span> <span class="ident">thread_rng</span>();
  137. <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;{}&quot;</span>, <span class="ident">rng</span>.<span class="ident">gen_bool</span>(<span class="number">1.0</span> <span class="op">/</span> <span class="number">3.0</span>));</pre>
  138. <h1 id="panics-1" class="section-header"><a href="#panics-1">Panics</a></h1>
  139. <p>If <code>p</code> &lt; 0 or <code>p</code> &gt; 1.</p>
  140. </div><h3 id='method.choose' class='method'><span id='choose.v' class='invisible'><code>fn <a href='#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;</code></span></h3><div class='docblock'><p>Return a random element from <code>values</code>.</p>
  141. <p>Return <code>None</code> if <code>values</code> is empty.</p>
  142. <h1 id="example-7" class="section-header"><a href="#example-7">Example</a></h1>
  143. <pre class="rust rust-example-rendered">
  144. <span class="kw">use</span> <span class="ident">rand</span>::{<span class="ident">thread_rng</span>, <span class="ident">Rng</span>};
  145. <span class="kw">let</span> <span class="ident">choices</span> <span class="op">=</span> [<span class="number">1</span>, <span class="number">2</span>, <span class="number">4</span>, <span class="number">8</span>, <span class="number">16</span>, <span class="number">32</span>];
  146. <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">rng</span> <span class="op">=</span> <span class="ident">thread_rng</span>();
  147. <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;{:?}&quot;</span>, <span class="ident">rng</span>.<span class="ident">choose</span>(<span class="kw-2">&amp;</span><span class="ident">choices</span>));
  148. <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">rng</span>.<span class="ident">choose</span>(<span class="kw-2">&amp;</span><span class="ident">choices</span>[..<span class="number">0</span>]), <span class="prelude-val">None</span>);</pre>
  149. </div><h3 id='method.choose_mut' class='method'><span id='choose_mut.v' class='invisible'><code>fn <a href='#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;</code></span></h3><div class='docblock'><p>Return a mutable pointer to a random element from <code>values</code>.</p>
  150. <p>Return <code>None</code> if <code>values</code> is empty.</p>
  151. </div><h3 id='method.shuffle' class='method'><span id='shuffle.v' class='invisible'><code>fn <a href='#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>)</code></span></h3><div class='docblock'><p>Shuffle a mutable slice in place.</p>
  152. <p>This applies Durstenfeld's algorithm for the <a href="https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#The_modern_algorithm">Fisher–Yates shuffle</a>
  153. which produces an unbiased permutation.</p>
  154. <h1 id="example-8" class="section-header"><a href="#example-8">Example</a></h1>
  155. <pre class="rust rust-example-rendered">
  156. <span class="kw">use</span> <span class="ident">rand</span>::{<span class="ident">thread_rng</span>, <span class="ident">Rng</span>};
  157. <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">rng</span> <span class="op">=</span> <span class="ident">thread_rng</span>();
  158. <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">y</span> <span class="op">=</span> [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>];
  159. <span class="ident">rng</span>.<span class="ident">shuffle</span>(<span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="ident">y</span>);
  160. <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;{:?}&quot;</span>, <span class="ident">y</span>);
  161. <span class="ident">rng</span>.<span class="ident">shuffle</span>(<span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="ident">y</span>);
  162. <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;{:?}&quot;</span>, <span class="ident">y</span>);</pre>
  163. </div><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;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;T, R&gt;</h3><code class="content"><span class="where fmt-newline">impl&lt;T, R:&nbsp;<a class="trait" href="../rand/trait.RngCore.html" title="trait rand::RngCore">RngCore</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;T, R&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;<a class="struct" href="../rand/distributions/struct.Standard.html" title="struct rand::distributions::Standard">Standard</a>: <a class="trait" href="../rand/distributions/trait.Distribution.html" title="trait rand::distributions::Distribution">Distribution</a>&lt;T&gt;,&nbsp;</span></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><h3 id='method.gen_iter' class='method'><span id='gen_iter.v' class='invisible'><code>fn <a href='#method.gen_iter' class='fnname'>gen_iter</a>&lt;T&gt;(&amp;mut self) -&gt; <a class="struct" href="../rand/struct.Generator.html" title="struct rand::Generator">Generator</a>&lt;T, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;mut </a>Self&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;<a class="struct" href="../rand/distributions/struct.Standard.html" title="struct rand::distributions::Standard">Standard</a>: <a class="trait" href="../rand/distributions/trait.Distribution.html" title="trait rand::distributions::Distribution">Distribution</a>&lt;T&gt;,&nbsp;</span></code></span></h3><div class='stability'><div class='stab deprecated'>Deprecated since 0.5.0<p>: use Rng::sample_iter(&amp;Standard) instead</p>
  164. </div></div><div class='docblock'><p>Return an iterator that will yield an infinite number of randomly
  165. generated items.</p>
  166. <h1 id="example-9" class="section-header"><a href="#example-9">Example</a></h1>
  167. <pre class="rust rust-example-rendered">
  168. <span class="kw">use</span> <span class="ident">rand</span>::{<span class="ident">thread_rng</span>, <span class="ident">Rng</span>};
  169. <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">rng</span> <span class="op">=</span> <span class="ident">thread_rng</span>();
  170. <span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="ident">rng</span>.<span class="ident">gen_iter</span>::<span class="op">&lt;</span><span class="ident">u32</span><span class="op">&gt;</span>().<span class="ident">take</span>(<span class="number">10</span>).<span class="ident">collect</span>::<span class="op">&lt;</span><span class="ident">Vec</span><span class="op">&lt;</span><span class="ident">u32</span><span class="op">&gt;&gt;</span>();
  171. <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;{:?}&quot;</span>, <span class="ident">x</span>);
  172. <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;{:?}&quot;</span>, <span class="ident">rng</span>.<span class="ident">gen_iter</span>::<span class="op">&lt;</span>(<span class="ident">f64</span>, <span class="ident">bool</span>)<span class="op">&gt;</span>().<span class="ident">take</span>(<span class="number">5</span>)
  173. .<span class="ident">collect</span>::<span class="op">&lt;</span><span class="ident">Vec</span><span class="op">&lt;</span>(<span class="ident">f64</span>, <span class="ident">bool</span>)<span class="op">&gt;&gt;</span>());</pre>
  174. </div><h3 id='method.gen_weighted_bool' class='method'><span id='gen_weighted_bool.v' class='invisible'><code>fn <a href='#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></code></span></h3><div class='stability'><div class='stab deprecated'>Deprecated since 0.5.0<p>: use gen_bool instead</p>
  175. </div></div><div class='docblock'><p>Return a bool with a 1 in n chance of true</p>
  176. <h1 id="example-10" class="section-header"><a href="#example-10">Example</a></h1>
  177. <pre class="rust rust-example-rendered">
  178. <span class="kw">use</span> <span class="ident">rand</span>::{<span class="ident">thread_rng</span>, <span class="ident">Rng</span>};
  179. <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">rng</span> <span class="op">=</span> <span class="ident">thread_rng</span>();
  180. <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">rng</span>.<span class="ident">gen_weighted_bool</span>(<span class="number">0</span>), <span class="bool-val">true</span>);
  181. <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">rng</span>.<span class="ident">gen_weighted_bool</span>(<span class="number">1</span>), <span class="bool-val">true</span>);
  182. <span class="comment">// Just like `rng.gen::&lt;bool&gt;()` a 50-50% chance, but using a slower</span>
  183. <span class="comment">// method with different results.</span>
  184. <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;{}&quot;</span>, <span class="ident">rng</span>.<span class="ident">gen_weighted_bool</span>(<span class="number">2</span>));
  185. <span class="comment">// First meaningful use of `gen_weighted_bool`.</span>
  186. <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;{}&quot;</span>, <span class="ident">rng</span>.<span class="ident">gen_weighted_bool</span>(<span class="number">3</span>));</pre>
  187. </div><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;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;R&gt;</h3><code class="content"><span class="where fmt-newline">impl&lt;R:&nbsp;<a class="trait" href="../rand/trait.RngCore.html" title="trait rand::RngCore">RngCore</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;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><h3 id='method.gen_ascii_chars' class='method'><span id='gen_ascii_chars.v' class='invisible'><code>fn <a href='#method.gen_ascii_chars' class='fnname'>gen_ascii_chars</a>(&amp;mut self) -&gt; <a class="struct" href="../rand/struct.AsciiGenerator.html" title="struct rand::AsciiGenerator">AsciiGenerator</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;mut </a>Self&gt;</code></span></h3><div class='stability'><div class='stab deprecated'>Deprecated since 0.5.0<p>: use sample_iter(&amp;Alphanumeric) instead</p>
  188. </div></div><div class='docblock'><p>Return an iterator of random characters from the set A-Z,a-z,0-9.</p>
  189. <h1 id="example-11" class="section-header"><a href="#example-11">Example</a></h1>
  190. <pre class="rust rust-example-rendered">
  191. <span class="kw">use</span> <span class="ident">rand</span>::{<span class="ident">thread_rng</span>, <span class="ident">Rng</span>};
  192. <span class="kw">let</span> <span class="ident">s</span>: <span class="ident">String</span> <span class="op">=</span> <span class="ident">thread_rng</span>().<span class="ident">gen_ascii_chars</span>().<span class="ident">take</span>(<span class="number">10</span>).<span class="ident">collect</span>();
  193. <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;{}&quot;</span>, <span class="ident">s</span>);</pre>
  194. </div></div>
  195. <h2 id='implementors' class='small-section-header'>
  196. Implementors<a href='#implementors' class='anchor'></a>
  197. </h2>
  198. <ul class='item-list' id='implementors-list'>
  199. <li><table class='table-display'><tbody><tr><td><code>impl&lt;R:&nbsp;<a class="trait" href="../rand/trait.RngCore.html" title="trait rand::RngCore">RngCore</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>&gt; Rng for R</code><td><div class='out-of-band'><a class='srclink' href='../src/rand/lib.rs.html#725' title='goto source code'>[src]</a></div></td></tr></tbody></table></li>
  200. </ul><script type="text/javascript">window.inlined_types=new Set([]);</script><script type="text/javascript" async
  201. src="../implementors/rand/trait.Rng.js">
  202. </script></section><section id="search" class="content hidden"></section><section class="footer"></section><aside id="help" class="hidden"><div><h1 class="hidden">Help</h1><div class="shortcuts"><h2>Keyboard Shortcuts</h2><dl><dt><kbd>?</kbd></dt><dd>Show this help dialog</dd><dt><kbd>S</kbd></dt><dd>Focus the search field</dd><dt><kbd>↑</kbd></dt><dd>Move up in search results</dd><dt><kbd>↓</kbd></dt><dd>Move down in search results</dd><dt><kbd>↹</kbd></dt><dd>Switch tab</dd><dt><kbd>&#9166;</kbd></dt><dd>Go to active search result</dd><dt><kbd>+</kbd></dt><dd>Expand all sections</dd><dt><kbd>-</kbd></dt><dd>Collapse all sections</dd></dl></div><div class="infos"><h2>Search Tricks</h2><p>Prefix searches with a type followed by a colon (e.g. <code>fn:</code>) to restrict the search to a given type.</p><p>Accepted types are: <code>fn</code>, <code>mod</code>, <code>struct</code>, <code>enum</code>, <code>trait</code>, <code>type</code>, <code>macro</code>, and <code>const</code>.</p><p>Search functions by type signature (e.g. <code>vec -> usize</code> or <code>* -> vec</code>)</p><p>Search multiple things at once by splitting your query with comma (e.g. <code>str,u8</code> or <code>String,struct:Vec,test</code>)</p></div></div></aside><script>window.rootPath = "../";window.currentCrate = "rand";</script><script src="../aliases.js"></script><script src="../main.js"></script><script defer src="../search-index.js"></script></body></html>