blob: 7de7cb44af7313dab73aaa5c9fa51f6aa5bf9533 [file] [log] [blame]
<!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="Extension trait on slices, providing random mutation and sampling methods."><meta name="keywords" content="rust, rustlang, rust-lang, SliceRandom"><title>SliceRandom in rand::seq - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" href="../../normalize.css"><link rel="stylesheet" href="../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" href="../../ayu.css" disabled><link rel="stylesheet" href="../../dark.css" disabled><link rel="stylesheet" href="../../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../../storage.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../main.js"></script><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="icon" href="https://www.rust-lang.org/favicon.ico"></head><body class="rustdoc trait"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">&#9776;</button><a class="sidebar-logo" href="../../rand/index.html"><div class="logo-container"><img src="https://www.rust-lang.org/logos/rust-logo-128x128-blk.png" alt="logo"></div></a><h2></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../../rand/index.html"><div class="logo-container">
<img src="https://www.rust-lang.org/logos/rust-logo-128x128-blk.png" alt="logo"></div></a><h2 class="location"><a href="#">SliceRandom</a></h2><div class="sidebar-elems"><section><h3><a href="#required-associated-types">Required Associated Types</a></h3><ul class="block"><li><a href="#associatedtype.Item">Item</a></li></ul><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.choose">choose</a></li><li><a href="#tymethod.choose_multiple">choose_multiple</a></li><li><a href="#tymethod.choose_multiple_weighted">choose_multiple_weighted</a></li><li><a href="#tymethod.choose_mut">choose_mut</a></li><li><a href="#tymethod.choose_weighted">choose_weighted</a></li><li><a href="#tymethod.choose_weighted_mut">choose_weighted_mut</a></li><li><a href="#tymethod.partial_shuffle">partial_shuffle</a></li><li><a href="#tymethod.shuffle">shuffle</a></li></ul><h3><a href="#foreign-impls">Implementations on Foreign Types</a></h3><ul class="block"><li><a href="#impl-SliceRandom-for-%5BT%5D">[T]</a></li></ul><h3><a href="#implementors">Implementors</a></h3></section><h2><a href="index.html">In rand::seq</a></h2></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../wheel.svg"></a></div></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1 class="fqn">Trait <a href="../index.html">rand</a>::<wbr><a href="index.html">seq</a>::<wbr><a class="trait" href="#">SliceRandom</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../../clipboard.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="srclink" href="../../src/rand/seq/mod.rs.html#59-268">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span></div><div class="item-decl"><pre class="rust trait"><code>pub trait SliceRandom {
type <a href="#associatedtype.Item" class="associatedtype">Item</a>;
fn <a href="#tymethod.choose" class="fnname">choose</a>&lt;R&gt;(&amp;self, rng: &amp;mut R) -&gt; Option&lt;&amp;Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type rand::seq::SliceRandom::Item">Item</a>&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="where">where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;R: <a class="trait" href="../trait.Rng.html" title="trait rand::Rng">Rng</a> + ?Sized</span>;
<span class="item-spacer"></span> fn <a href="#tymethod.choose_mut" class="fnname">choose_mut</a>&lt;R&gt;(&amp;mut self, rng: &amp;mut R) -&gt; Option&lt;&amp;mut Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type rand::seq::SliceRandom::Item">Item</a>&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="where">where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;R: <a class="trait" href="../trait.Rng.html" title="trait rand::Rng">Rng</a> + ?Sized</span>;
<span class="item-spacer"></span> fn <a href="#tymethod.choose_multiple" class="fnname">choose_multiple</a>&lt;R&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;self,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rng: &amp;mut R,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;amount: usize<br>&nbsp;&nbsp;&nbsp;&nbsp;) -&gt; <a class="struct" href="struct.SliceChooseIter.html" title="struct rand::seq::SliceChooseIter">SliceChooseIter</a>&lt;'_, Self, Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type rand::seq::SliceRandom::Item">Item</a>&gt;<span class="notable-traits"><span class="notable-traits-tooltip"><span class="notable-traits-tooltiptext"><span class="docblock"><span class="notable">Notable traits for <a class="struct" href="struct.SliceChooseIter.html" title="struct rand::seq::SliceChooseIter">SliceChooseIter</a>&lt;'a, S, T&gt;</span><code class="content"><span class="where fmt-newline">impl&lt;'a, S:&nbsp;Index&lt;usize, Output = T&gt; + ?Sized + 'a, T:&nbsp;'a&gt; Iterator for <a class="struct" href="struct.SliceChooseIter.html" title="struct rand::seq::SliceChooseIter">SliceChooseIter</a>&lt;'a, S, T&gt;</span><span class="where fmt-newline"> type <a class="associatedtype">Item</a> = &amp;'a T;</span></code></span></span></span></span><br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="where">where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;R: <a class="trait" href="../trait.Rng.html" title="trait rand::Rng">Rng</a> + ?Sized</span>;
<span class="item-spacer"></span> fn <a href="#tymethod.choose_weighted" class="fnname">choose_weighted</a>&lt;R, F, B, X&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;self,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rng: &amp;mut R,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;weight: F<br>&nbsp;&nbsp;&nbsp;&nbsp;) -&gt; Result&lt;&amp;Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type rand::seq::SliceRandom::Item">Item</a>, <a class="enum" href="../distributions/weighted/enum.WeightedError.html" title="enum rand::distributions::weighted::WeightedError">WeightedError</a>&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="where">where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;R: <a class="trait" href="../trait.Rng.html" title="trait rand::Rng">Rng</a> + ?Sized,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;F: Fn(&amp;Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type rand::seq::SliceRandom::Item">Item</a>) -&gt; B,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;B: <a class="trait" href="../distributions/uniform/trait.SampleBorrow.html" title="trait rand::distributions::uniform::SampleBorrow">SampleBorrow</a>&lt;X&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;X: <a class="trait" href="../distributions/uniform/trait.SampleUniform.html" title="trait rand::distributions::uniform::SampleUniform">SampleUniform</a> + for&lt;'a&gt; AddAssign&lt;&amp;'a X&gt; + PartialOrd&lt;X&gt; + Clone + Default</span>;
<span class="item-spacer"></span> fn <a href="#tymethod.choose_weighted_mut" class="fnname">choose_weighted_mut</a>&lt;R, F, B, X&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;mut self,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rng: &amp;mut R,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;weight: F<br>&nbsp;&nbsp;&nbsp;&nbsp;) -&gt; Result&lt;&amp;mut Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type rand::seq::SliceRandom::Item">Item</a>, <a class="enum" href="../distributions/weighted/enum.WeightedError.html" title="enum rand::distributions::weighted::WeightedError">WeightedError</a>&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="where">where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;R: <a class="trait" href="../trait.Rng.html" title="trait rand::Rng">Rng</a> + ?Sized,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;F: Fn(&amp;Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type rand::seq::SliceRandom::Item">Item</a>) -&gt; B,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;B: <a class="trait" href="../distributions/uniform/trait.SampleBorrow.html" title="trait rand::distributions::uniform::SampleBorrow">SampleBorrow</a>&lt;X&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;X: <a class="trait" href="../distributions/uniform/trait.SampleUniform.html" title="trait rand::distributions::uniform::SampleUniform">SampleUniform</a> + for&lt;'a&gt; AddAssign&lt;&amp;'a X&gt; + PartialOrd&lt;X&gt; + Clone + Default</span>;
<span class="item-spacer"></span> fn <a href="#tymethod.choose_multiple_weighted" class="fnname">choose_multiple_weighted</a>&lt;R, F, X&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;self,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rng: &amp;mut R,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;amount: usize,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;weight: F<br>&nbsp;&nbsp;&nbsp;&nbsp;) -&gt; Result&lt;<a class="struct" href="struct.SliceChooseIter.html" title="struct rand::seq::SliceChooseIter">SliceChooseIter</a>&lt;'_, Self, Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type rand::seq::SliceRandom::Item">Item</a>&gt;, <a class="enum" href="../distributions/weighted/enum.WeightedError.html" title="enum rand::distributions::weighted::WeightedError">WeightedError</a>&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="where">where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;R: <a class="trait" href="../trait.Rng.html" title="trait rand::Rng">Rng</a> + ?Sized,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;F: Fn(&amp;Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type rand::seq::SliceRandom::Item">Item</a>) -&gt; X,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;X: Into&lt;f64&gt;</span>;
<span class="item-spacer"></span> fn <a href="#tymethod.shuffle" class="fnname">shuffle</a>&lt;R&gt;(&amp;mut self, rng: &amp;mut R)<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="where">where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;R: <a class="trait" href="../trait.Rng.html" title="trait rand::Rng">Rng</a> + ?Sized</span>;
<span class="item-spacer"></span> fn <a href="#tymethod.partial_shuffle" class="fnname">partial_shuffle</a>&lt;R&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;mut self,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rng: &amp;mut R,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;amount: usize<br>&nbsp;&nbsp;&nbsp;&nbsp;) -&gt; (&amp;mut [Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type rand::seq::SliceRandom::Item">Item</a>], &amp;mut [Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type rand::seq::SliceRandom::Item">Item</a>])<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="where">where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;R: <a class="trait" href="../trait.Rng.html" title="trait rand::Rng">Rng</a> + ?Sized</span>;
}</code></pre></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Extension trait on slices, providing random mutation and sampling methods.</p>
<p>This trait is implemented on all <code>[T]</code> slice types, providing several
methods for choosing and shuffling elements. You must <code>use</code> this trait:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>rand::seq::SliceRandom;
<span class="kw">let </span><span class="kw-2">mut </span>rng = rand::thread_rng();
<span class="kw">let </span><span class="kw-2">mut </span>bytes = <span class="string">&quot;Hello, random!&quot;</span>.to_string().into_bytes();
bytes.shuffle(<span class="kw-2">&amp;mut </span>rng);
<span class="kw">let </span>str = String::from_utf8(bytes).unwrap();
<span class="macro">println!</span>(<span class="string">&quot;{}&quot;</span>, str);</code></pre></div>
<p>Example output (non-deterministic):</p>
<div class="example-wrap"><pre class="language-none"><code>l,nmroHado !le</code></pre></div></div></details><h2 id="required-associated-types" class="small-section-header">Required Associated Types<a href="#required-associated-types" class="anchor"></a></h2><div class="methods"><details class="rustdoc-toggle method-toggle" open><summary><section id="associatedtype.Item" class="method has-srclink"><a class="srclink rightside" href="../../src/rand/seq/mod.rs.html#61">source</a><h4 class="code-header">type <a href="#associatedtype.Item" class="associatedtype">Item</a></h4></section></summary><div class="docblock"><p>The element type.</p>
</div></details></div><h2 id="required-methods" class="small-section-header">Required Methods<a href="#required-methods" class="anchor"></a></h2><div class="methods"><details class="rustdoc-toggle method-toggle" open><summary><section id="tymethod.choose" class="method has-srclink"><a class="srclink rightside" href="../../src/rand/seq/mod.rs.html#79-80">source</a><h4 class="code-header">fn <a href="#tymethod.choose" class="fnname">choose</a>&lt;R&gt;(&amp;self, rng: &amp;mut R) -&gt; Option&lt;&amp;Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type rand::seq::SliceRandom::Item">Item</a>&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;R: <a class="trait" href="../trait.Rng.html" title="trait rand::Rng">Rng</a> + ?Sized,</span></h4></section></summary><div class="docblock"><p>Returns a reference to one random element of the slice, or <code>None</code> if the
slice is empty.</p>
<p>For slices, complexity is <code>O(1)</code>.</p>
<h5 id="example"><a href="#example">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>rand::thread_rng;
<span class="kw">use </span>rand::seq::SliceRandom;
<span class="kw">let </span>choices = [<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>];
<span class="kw">let </span><span class="kw-2">mut </span>rng = thread_rng();
<span class="macro">println!</span>(<span class="string">&quot;{:?}&quot;</span>, choices.choose(<span class="kw-2">&amp;mut </span>rng));
<span class="macro">assert_eq!</span>(choices[..<span class="number">0</span>].choose(<span class="kw-2">&amp;mut </span>rng), <span class="prelude-val">None</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="tymethod.choose_mut" class="method has-srclink"><a class="srclink rightside" href="../../src/rand/seq/mod.rs.html#86-87">source</a><h4 class="code-header">fn <a href="#tymethod.choose_mut" class="fnname">choose_mut</a>&lt;R&gt;(&amp;mut self, rng: &amp;mut R) -&gt; Option&lt;&amp;mut Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type rand::seq::SliceRandom::Item">Item</a>&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;R: <a class="trait" href="../trait.Rng.html" title="trait rand::Rng">Rng</a> + ?Sized,</span></h4></section></summary><div class="docblock"><p>Returns a mutable reference to one random element of the slice, or
<code>None</code> if the slice is empty.</p>
<p>For slices, complexity is <code>O(1)</code>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="tymethod.choose_multiple" class="method has-srclink"><a class="srclink rightside" href="../../src/rand/seq/mod.rs.html#115-116">source</a><h4 class="code-header">fn <a href="#tymethod.choose_multiple" class="fnname">choose_multiple</a>&lt;R&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self,<br>&nbsp;&nbsp;&nbsp;&nbsp;rng: &amp;mut R,<br>&nbsp;&nbsp;&nbsp;&nbsp;amount: usize<br>) -&gt; <a class="struct" href="struct.SliceChooseIter.html" title="struct rand::seq::SliceChooseIter">SliceChooseIter</a>&lt;'_, Self, Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type rand::seq::SliceRandom::Item">Item</a>&gt;<span class="notable-traits"><span class="notable-traits-tooltip"><span class="notable-traits-tooltiptext"><span class="docblock"><span class="notable">Notable traits for <a class="struct" href="struct.SliceChooseIter.html" title="struct rand::seq::SliceChooseIter">SliceChooseIter</a>&lt;'a, S, T&gt;</span><code class="content"><span class="where fmt-newline">impl&lt;'a, S:&nbsp;Index&lt;usize, Output = T&gt; + ?Sized + 'a, T:&nbsp;'a&gt; Iterator for <a class="struct" href="struct.SliceChooseIter.html" title="struct rand::seq::SliceChooseIter">SliceChooseIter</a>&lt;'a, S, T&gt;</span><span class="where fmt-newline"> type <a class="associatedtype">Item</a> = &amp;'a T;</span></code></span></span></span></span><span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;R: <a class="trait" href="../trait.Rng.html" title="trait rand::Rng">Rng</a> + ?Sized,</span></h4></section></summary><div class="docblock"><p>Chooses <code>amount</code> elements from the slice at random, without repetition,
and in random order. The returned iterator is appropriate both for
collection into a <code>Vec</code> and filling an existing buffer (see example).</p>
<p>In case this API is not sufficiently flexible, use <a href="index/fn.sample.html" title="index::sample"><code>index::sample</code></a>.</p>
<p>For slices, complexity is the same as <a href="index/fn.sample.html" title="index::sample"><code>index::sample</code></a>.</p>
<h5 id="example-1"><a href="#example-1">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>rand::seq::SliceRandom;
<span class="kw">let </span><span class="kw-2">mut </span>rng = <span class="kw-2">&amp;mut </span>rand::thread_rng();
<span class="kw">let </span>sample = <span class="string">&quot;Hello, audience!&quot;</span>.as_bytes();
<span class="comment">// collect the results into a vector:
</span><span class="kw">let </span>v: Vec&lt;u8&gt; = sample.choose_multiple(<span class="kw-2">&amp;mut </span>rng, <span class="number">3</span>).cloned().collect();
<span class="comment">// store in a buffer:
</span><span class="kw">let </span><span class="kw-2">mut </span>buf = [<span class="number">0u8</span>; <span class="number">5</span>];
<span class="kw">for </span>(b, slot) <span class="kw">in </span>sample.choose_multiple(<span class="kw-2">&amp;mut </span>rng, buf.len()).zip(buf.iter_mut()) {
<span class="kw-2">*</span>slot = <span class="kw-2">*</span>b;
}</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="tymethod.choose_weighted" class="method has-srclink"><a class="srclink rightside" href="../../src/rand/seq/mod.rs.html#143-154">source</a><h4 class="code-header">fn <a href="#tymethod.choose_weighted" class="fnname">choose_weighted</a>&lt;R, F, B, X&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self,<br>&nbsp;&nbsp;&nbsp;&nbsp;rng: &amp;mut R,<br>&nbsp;&nbsp;&nbsp;&nbsp;weight: F<br>) -&gt; Result&lt;&amp;Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type rand::seq::SliceRandom::Item">Item</a>, <a class="enum" href="../distributions/weighted/enum.WeightedError.html" title="enum rand::distributions::weighted::WeightedError">WeightedError</a>&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;R: <a class="trait" href="../trait.Rng.html" title="trait rand::Rng">Rng</a> + ?Sized,<br>&nbsp;&nbsp;&nbsp;&nbsp;F: Fn(&amp;Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type rand::seq::SliceRandom::Item">Item</a>) -&gt; B,<br>&nbsp;&nbsp;&nbsp;&nbsp;B: <a class="trait" href="../distributions/uniform/trait.SampleBorrow.html" title="trait rand::distributions::uniform::SampleBorrow">SampleBorrow</a>&lt;X&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;X: <a class="trait" href="../distributions/uniform/trait.SampleUniform.html" title="trait rand::distributions::uniform::SampleUniform">SampleUniform</a> + for&lt;'a&gt; AddAssign&lt;&amp;'a X&gt; + PartialOrd&lt;X&gt; + Clone + Default,</span></h4></section></summary><div class="docblock"><p>Similar to <a href="trait.SliceRandom.html#tymethod.choose"><code>choose</code></a>, but where the likelihood of each outcome may be
specified.</p>
<p>The specified function <code>weight</code> maps each item <code>x</code> to a relative
likelihood <code>weight(x)</code>. The probability of each item being selected is
therefore <code>weight(x) / s</code>, where <code>s</code> is the sum of all <code>weight(x)</code>.</p>
<p>For slices of length <code>n</code>, complexity is <code>O(n)</code>.
See also <a href="trait.SliceRandom.html#tymethod.choose_weighted_mut"><code>choose_weighted_mut</code></a>, <a href="../distributions/weighted/index.html"><code>distributions::weighted</code></a>.</p>
<h5 id="example-2"><a href="#example-2">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>rand::prelude::<span class="kw-2">*</span>;
<span class="kw">let </span>choices = [(<span class="string">&#39;a&#39;</span>, <span class="number">2</span>), (<span class="string">&#39;b&#39;</span>, <span class="number">1</span>), (<span class="string">&#39;c&#39;</span>, <span class="number">1</span>)];
<span class="kw">let </span><span class="kw-2">mut </span>rng = thread_rng();
<span class="comment">// 50% chance to print &#39;a&#39;, 25% chance to print &#39;b&#39;, 25% chance to print &#39;c&#39;
</span><span class="macro">println!</span>(<span class="string">&quot;{:?}&quot;</span>, choices.choose_weighted(<span class="kw-2">&amp;mut </span>rng, |item| item.<span class="number">1</span>).unwrap().<span class="number">0</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="tymethod.choose_weighted_mut" class="method has-srclink"><a class="srclink rightside" href="../../src/rand/seq/mod.rs.html#171-182">source</a><h4 class="code-header">fn <a href="#tymethod.choose_weighted_mut" class="fnname">choose_weighted_mut</a>&lt;R, F, B, X&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;mut self,<br>&nbsp;&nbsp;&nbsp;&nbsp;rng: &amp;mut R,<br>&nbsp;&nbsp;&nbsp;&nbsp;weight: F<br>) -&gt; Result&lt;&amp;mut Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type rand::seq::SliceRandom::Item">Item</a>, <a class="enum" href="../distributions/weighted/enum.WeightedError.html" title="enum rand::distributions::weighted::WeightedError">WeightedError</a>&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;R: <a class="trait" href="../trait.Rng.html" title="trait rand::Rng">Rng</a> + ?Sized,<br>&nbsp;&nbsp;&nbsp;&nbsp;F: Fn(&amp;Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type rand::seq::SliceRandom::Item">Item</a>) -&gt; B,<br>&nbsp;&nbsp;&nbsp;&nbsp;B: <a class="trait" href="../distributions/uniform/trait.SampleBorrow.html" title="trait rand::distributions::uniform::SampleBorrow">SampleBorrow</a>&lt;X&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;X: <a class="trait" href="../distributions/uniform/trait.SampleUniform.html" title="trait rand::distributions::uniform::SampleUniform">SampleUniform</a> + for&lt;'a&gt; AddAssign&lt;&amp;'a X&gt; + PartialOrd&lt;X&gt; + Clone + Default,</span></h4></section></summary><div class="docblock"><p>Similar to <a href="trait.SliceRandom.html#tymethod.choose_mut"><code>choose_mut</code></a>, but where the likelihood of each outcome may
be specified.</p>
<p>The specified function <code>weight</code> maps each item <code>x</code> to a relative
likelihood <code>weight(x)</code>. The probability of each item being selected is
therefore <code>weight(x) / s</code>, where <code>s</code> is the sum of all <code>weight(x)</code>.</p>
<p>For slices of length <code>n</code>, complexity is <code>O(n)</code>.
See also <a href="trait.SliceRandom.html#tymethod.choose_weighted"><code>choose_weighted</code></a>, <a href="../distributions/weighted/index.html"><code>distributions::weighted</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="tymethod.choose_multiple_weighted" class="method has-srclink"><a class="srclink rightside" href="../../src/rand/seq/mod.rs.html#220-226">source</a><h4 class="code-header">fn <a href="#tymethod.choose_multiple_weighted" class="fnname">choose_multiple_weighted</a>&lt;R, F, X&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self,<br>&nbsp;&nbsp;&nbsp;&nbsp;rng: &amp;mut R,<br>&nbsp;&nbsp;&nbsp;&nbsp;amount: usize,<br>&nbsp;&nbsp;&nbsp;&nbsp;weight: F<br>) -&gt; Result&lt;<a class="struct" href="struct.SliceChooseIter.html" title="struct rand::seq::SliceChooseIter">SliceChooseIter</a>&lt;'_, Self, Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type rand::seq::SliceRandom::Item">Item</a>&gt;, <a class="enum" href="../distributions/weighted/enum.WeightedError.html" title="enum rand::distributions::weighted::WeightedError">WeightedError</a>&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;R: <a class="trait" href="../trait.Rng.html" title="trait rand::Rng">Rng</a> + ?Sized,<br>&nbsp;&nbsp;&nbsp;&nbsp;F: Fn(&amp;Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type rand::seq::SliceRandom::Item">Item</a>) -&gt; X,<br>&nbsp;&nbsp;&nbsp;&nbsp;X: Into&lt;f64&gt;,</span></h4></section></summary><div class="docblock"><p>Similar to <a href="trait.SliceRandom.html#tymethod.choose_multiple"><code>choose_multiple</code></a>, but where the likelihood of each element’s
inclusion in the output may be specified. The elements are returned in an
arbitrary, unspecified order.</p>
<p>The specified function <code>weight</code> maps each item <code>x</code> to a relative
likelihood <code>weight(x)</code>. The probability of each item being selected is
therefore <code>weight(x) / s</code>, where <code>s</code> is the sum of all <code>weight(x)</code>.</p>
<p>If all of the weights are equal, even if they are all zero, each element has
an equal likelihood of being selected.</p>
<p>The complexity of this method depends on the feature <code>partition_at_index</code>.
If the feature is enabled, then for slices of length <code>n</code>, the complexity
is <code>O(n)</code> space and <code>O(n)</code> time. Otherwise, the complexity is <code>O(n)</code> space and
<code>O(n * log amount)</code> time.</p>
<h5 id="example-3"><a href="#example-3">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>rand::prelude::<span class="kw-2">*</span>;
<span class="kw">let </span>choices = [(<span class="string">&#39;a&#39;</span>, <span class="number">2</span>), (<span class="string">&#39;b&#39;</span>, <span class="number">1</span>), (<span class="string">&#39;c&#39;</span>, <span class="number">1</span>)];
<span class="kw">let </span><span class="kw-2">mut </span>rng = thread_rng();
<span class="comment">// First Draw * Second Draw = total odds
// -----------------------
// (50% * 50%) + (25% * 67%) = 41.7% chance that the output is `[&#39;a&#39;, &#39;b&#39;]` in some order.
// (50% * 50%) + (25% * 67%) = 41.7% chance that the output is `[&#39;a&#39;, &#39;c&#39;]` in some order.
// (25% * 33%) + (25% * 33%) = 16.6% chance that the output is `[&#39;b&#39;, &#39;c&#39;]` in some order.
</span><span class="macro">println!</span>(<span class="string">&quot;{:?}&quot;</span>, choices.choose_multiple_weighted(<span class="kw-2">&amp;mut </span>rng, <span class="number">2</span>, |item| item.<span class="number">1</span>).unwrap().collect::&lt;Vec&lt;<span class="kw">_</span>&gt;&gt;());</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="tymethod.shuffle" class="method has-srclink"><a class="srclink rightside" href="../../src/rand/seq/mod.rs.html#244-245">source</a><h4 class="code-header">fn <a href="#tymethod.shuffle" class="fnname">shuffle</a>&lt;R&gt;(&amp;mut self, rng: &amp;mut R)<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;R: <a class="trait" href="../trait.Rng.html" title="trait rand::Rng">Rng</a> + ?Sized,</span></h4></section></summary><div class="docblock"><p>Shuffle a mutable slice in place.</p>
<p>For slices of length <code>n</code>, complexity is <code>O(n)</code>.</p>
<h5 id="example-4"><a href="#example-4">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>rand::seq::SliceRandom;
<span class="kw">use </span>rand::thread_rng;
<span class="kw">let </span><span class="kw-2">mut </span>rng = thread_rng();
<span class="kw">let </span><span class="kw-2">mut </span>y = [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>];
<span class="macro">println!</span>(<span class="string">&quot;Unshuffled: {:?}&quot;</span>, y);
y.shuffle(<span class="kw-2">&amp;mut </span>rng);
<span class="macro">println!</span>(<span class="string">&quot;Shuffled: {:?}&quot;</span>, y);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="tymethod.partial_shuffle" class="method has-srclink"><a class="srclink rightside" href="../../src/rand/seq/mod.rs.html#264-267">source</a><h4 class="code-header">fn <a href="#tymethod.partial_shuffle" class="fnname">partial_shuffle</a>&lt;R&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;mut self,<br>&nbsp;&nbsp;&nbsp;&nbsp;rng: &amp;mut R,<br>&nbsp;&nbsp;&nbsp;&nbsp;amount: usize<br>) -&gt; (&amp;mut [Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type rand::seq::SliceRandom::Item">Item</a>], &amp;mut [Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type rand::seq::SliceRandom::Item">Item</a>])<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;R: <a class="trait" href="../trait.Rng.html" title="trait rand::Rng">Rng</a> + ?Sized,</span></h4></section></summary><div class="docblock"><p>Shuffle a slice in place, but exit early.</p>
<p>Returns two mutable slices from the source slice. The first contains
<code>amount</code> elements randomly permuted. The second has the remaining
elements that are not fully shuffled.</p>
<p>This is an efficient method to select <code>amount</code> elements at random from
the slice, provided the slice may be mutated.</p>
<p>If you only need to choose elements randomly and <code>amount &gt; self.len()/2</code>
then you may improve performance by taking
<code>amount = values.len() - amount</code> and using only the second slice.</p>
<p>If <code>amount</code> is greater than the number of elements in the slice, this
will perform a full shuffle.</p>
<p>For slices, complexity is <code>O(m)</code> where <code>m = amount</code>.</p>
</div></details></div><h2 id="foreign-impls" class="small-section-header">Implementations on Foreign Types<a href="#foreign-impls" class="anchor"></a></h2><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-SliceRandom-for-%5BT%5D" class="impl has-srclink"><a class="srclink rightside" href="../../src/rand/seq/mod.rs.html#492-613">source</a><a href="#impl-SliceRandom-for-%5BT%5D" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="trait.SliceRandom.html" title="trait rand::seq::SliceRandom">SliceRandom</a> for [T]</h3></section></summary><div class="impl-items"><section id="associatedtype.Item-1" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Item-1" class="anchor"></a><h4 class="code-header">type <a href="#associatedtype.Item" class="associatedtype">Item</a> = T</h4></section><section id="method.choose" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/rand/seq/mod.rs.html#495-502">source</a><a href="#method.choose" class="anchor"></a><h4 class="code-header">fn <a href="#tymethod.choose" class="fnname">choose</a>&lt;R&gt;(&amp;self, rng: &amp;mut R) -&gt; Option&lt;&amp;Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type rand::seq::SliceRandom::Item">Item</a>&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;R: <a class="trait" href="../trait.Rng.html" title="trait rand::Rng">Rng</a> + ?Sized,</span></h4></section><section id="method.choose_mut" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/rand/seq/mod.rs.html#504-512">source</a><a href="#method.choose_mut" class="anchor"></a><h4 class="code-header">fn <a href="#tymethod.choose_mut" class="fnname">choose_mut</a>&lt;R&gt;(&amp;mut self, rng: &amp;mut R) -&gt; Option&lt;&amp;mut Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type rand::seq::SliceRandom::Item">Item</a>&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;R: <a class="trait" href="../trait.Rng.html" title="trait rand::Rng">Rng</a> + ?Sized,</span></h4></section><section id="method.choose_multiple" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/rand/seq/mod.rs.html#515-523">source</a><a href="#method.choose_multiple" class="anchor"></a><h4 class="code-header">fn <a href="#tymethod.choose_multiple" class="fnname">choose_multiple</a>&lt;R&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self,<br>&nbsp;&nbsp;&nbsp;&nbsp;rng: &amp;mut R,<br>&nbsp;&nbsp;&nbsp;&nbsp;amount: usize<br>) -&gt; <a class="struct" href="struct.SliceChooseIter.html" title="struct rand::seq::SliceChooseIter">SliceChooseIter</a>&lt;'_, Self, Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type rand::seq::SliceRandom::Item">Item</a>&gt;<span class="notable-traits"><span class="notable-traits-tooltip"><span class="notable-traits-tooltiptext"><span class="docblock"><span class="notable">Notable traits for <a class="struct" href="struct.SliceChooseIter.html" title="struct rand::seq::SliceChooseIter">SliceChooseIter</a>&lt;'a, S, T&gt;</span><code class="content"><span class="where fmt-newline">impl&lt;'a, S:&nbsp;Index&lt;usize, Output = T&gt; + ?Sized + 'a, T:&nbsp;'a&gt; Iterator for <a class="struct" href="struct.SliceChooseIter.html" title="struct rand::seq::SliceChooseIter">SliceChooseIter</a>&lt;'a, S, T&gt;</span><span class="where fmt-newline"> type <a class="associatedtype">Item</a> = &amp;'a T;</span></code></span></span></span></span><span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;R: <a class="trait" href="../trait.Rng.html" title="trait rand::Rng">Rng</a> + ?Sized,</span></h4></section><section id="method.choose_weighted" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/rand/seq/mod.rs.html#526-542">source</a><a href="#method.choose_weighted" class="anchor"></a><h4 class="code-header">fn <a href="#tymethod.choose_weighted" class="fnname">choose_weighted</a>&lt;R, F, B, X&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self,<br>&nbsp;&nbsp;&nbsp;&nbsp;rng: &amp;mut R,<br>&nbsp;&nbsp;&nbsp;&nbsp;weight: F<br>) -&gt; Result&lt;&amp;Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type rand::seq::SliceRandom::Item">Item</a>, <a class="enum" href="../distributions/weighted/enum.WeightedError.html" title="enum rand::distributions::weighted::WeightedError">WeightedError</a>&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;R: <a class="trait" href="../trait.Rng.html" title="trait rand::Rng">Rng</a> + ?Sized,<br>&nbsp;&nbsp;&nbsp;&nbsp;F: Fn(&amp;Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type rand::seq::SliceRandom::Item">Item</a>) -&gt; B,<br>&nbsp;&nbsp;&nbsp;&nbsp;B: <a class="trait" href="../distributions/uniform/trait.SampleBorrow.html" title="trait rand::distributions::uniform::SampleBorrow">SampleBorrow</a>&lt;X&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;X: <a class="trait" href="../distributions/uniform/trait.SampleUniform.html" title="trait rand::distributions::uniform::SampleUniform">SampleUniform</a> + for&lt;'a&gt; AddAssign&lt;&amp;'a X&gt; + PartialOrd&lt;X&gt; + Clone + Default,</span></h4></section><section id="method.choose_weighted_mut" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/rand/seq/mod.rs.html#545-561">source</a><a href="#method.choose_weighted_mut" class="anchor"></a><h4 class="code-header">fn <a href="#tymethod.choose_weighted_mut" class="fnname">choose_weighted_mut</a>&lt;R, F, B, X&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;mut self,<br>&nbsp;&nbsp;&nbsp;&nbsp;rng: &amp;mut R,<br>&nbsp;&nbsp;&nbsp;&nbsp;weight: F<br>) -&gt; Result&lt;&amp;mut Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type rand::seq::SliceRandom::Item">Item</a>, <a class="enum" href="../distributions/weighted/enum.WeightedError.html" title="enum rand::distributions::weighted::WeightedError">WeightedError</a>&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;R: <a class="trait" href="../trait.Rng.html" title="trait rand::Rng">Rng</a> + ?Sized,<br>&nbsp;&nbsp;&nbsp;&nbsp;F: Fn(&amp;Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type rand::seq::SliceRandom::Item">Item</a>) -&gt; B,<br>&nbsp;&nbsp;&nbsp;&nbsp;B: <a class="trait" href="../distributions/uniform/trait.SampleBorrow.html" title="trait rand::distributions::uniform::SampleBorrow">SampleBorrow</a>&lt;X&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;X: <a class="trait" href="../distributions/uniform/trait.SampleUniform.html" title="trait rand::distributions::uniform::SampleUniform">SampleUniform</a> + for&lt;'a&gt; AddAssign&lt;&amp;'a X&gt; + PartialOrd&lt;X&gt; + Clone + Default,</span></h4></section><section id="method.choose_multiple_weighted" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/rand/seq/mod.rs.html#564-584">source</a><a href="#method.choose_multiple_weighted" class="anchor"></a><h4 class="code-header">fn <a href="#tymethod.choose_multiple_weighted" class="fnname">choose_multiple_weighted</a>&lt;R, F, X&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self,<br>&nbsp;&nbsp;&nbsp;&nbsp;rng: &amp;mut R,<br>&nbsp;&nbsp;&nbsp;&nbsp;amount: usize,<br>&nbsp;&nbsp;&nbsp;&nbsp;weight: F<br>) -&gt; Result&lt;<a class="struct" href="struct.SliceChooseIter.html" title="struct rand::seq::SliceChooseIter">SliceChooseIter</a>&lt;'_, Self, Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type rand::seq::SliceRandom::Item">Item</a>&gt;, <a class="enum" href="../distributions/weighted/enum.WeightedError.html" title="enum rand::distributions::weighted::WeightedError">WeightedError</a>&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;R: <a class="trait" href="../trait.Rng.html" title="trait rand::Rng">Rng</a> + ?Sized,<br>&nbsp;&nbsp;&nbsp;&nbsp;F: Fn(&amp;Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type rand::seq::SliceRandom::Item">Item</a>) -&gt; X,<br>&nbsp;&nbsp;&nbsp;&nbsp;X: Into&lt;f64&gt;,</span></h4></section><section id="method.shuffle" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/rand/seq/mod.rs.html#586-592">source</a><a href="#method.shuffle" class="anchor"></a><h4 class="code-header">fn <a href="#tymethod.shuffle" class="fnname">shuffle</a>&lt;R&gt;(&amp;mut self, rng: &amp;mut R)<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;R: <a class="trait" href="../trait.Rng.html" title="trait rand::Rng">Rng</a> + ?Sized,</span></h4></section><section id="method.partial_shuffle" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/rand/seq/mod.rs.html#594-612">source</a><a href="#method.partial_shuffle" class="anchor"></a><h4 class="code-header">fn <a href="#tymethod.partial_shuffle" class="fnname">partial_shuffle</a>&lt;R&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;mut self,<br>&nbsp;&nbsp;&nbsp;&nbsp;rng: &amp;mut R,<br>&nbsp;&nbsp;&nbsp;&nbsp;amount: usize<br>) -&gt; (&amp;mut [Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type rand::seq::SliceRandom::Item">Item</a>], &amp;mut [Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type rand::seq::SliceRandom::Item">Item</a>])<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;R: <a class="trait" href="../trait.Rng.html" title="trait rand::Rng">Rng</a> + ?Sized,</span></h4></section></div></details><h2 id="implementors" class="small-section-header">Implementors<a href="#implementors" class="anchor"></a></h2><div id="implementors-list"></div><script src="../../implementors/rand/seq/trait.SliceRandom.js" data-ignore-extern-crates="core" async></script></section></div></main><div id="rustdoc-vars" data-root-path="../../" data-current-crate="rand" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.66.0-nightly (5c8bff74b 2022-10-21)" ></div></body></html>