mpvrc/rand/seq/trait.SliceRandom.html

237 lines
No EOL
51 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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."><title>SliceRandom in rand::seq - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="rand" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.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" title="show sidebar"></button><a class="logo-container" href="../../rand/index.html"><img src="https://www.rust-lang.org/logos/rust-logo-128x128-blk.png" alt=""></a></nav><nav class="sidebar"><div class="sidebar-crate"><a class="logo-container" href="../../rand/index.html"><img src="https://www.rust-lang.org/logos/rust-logo-128x128-blk.png" alt="logo"></a><h2><a href="../../rand/index.html">rand</a><span class="version">0.8.5</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Slice<wbr>Random</a></h2><h3><a href="#required-associated-types">Required Associated Types</a></h3><ul class="block"><li><a href="#associatedtype.Item" title="Item">Item</a></li></ul><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.choose" title="choose">choose</a></li><li><a href="#tymethod.choose_multiple" title="choose_multiple">choose_multiple</a></li><li><a href="#tymethod.choose_multiple_weighted" title="choose_multiple_weighted">choose_multiple_weighted</a></li><li><a href="#tymethod.choose_mut" title="choose_mut">choose_mut</a></li><li><a href="#tymethod.choose_weighted" title="choose_weighted">choose_weighted</a></li><li><a href="#tymethod.choose_weighted_mut" title="choose_weighted_mut">choose_weighted_mut</a></li><li><a href="#tymethod.partial_shuffle" title="partial_shuffle">partial_shuffle</a></li><li><a href="#tymethod.shuffle" title="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" title="[T]">[T]</a></li></ul><h3><a href="#dyn-compatibility">Dyn Compatibility</a></h3><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2><a href="index.html">In rand::<wbr>seq</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">rand</a>::<wbr><a href="index.html">seq</a></span><h1>Trait <span class="trait">SliceRandom</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/rand/seq/mod.rs.html#59-268">Source</a> </span></div><pre class="rust item-decl"><code>pub trait SliceRandom {
type <a href="#associatedtype.Item" class="associatedtype">Item</a>;
// Required methods
fn <a href="#tymethod.choose" class="fn">choose</a>&lt;R&gt;(&amp;self, rng: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;mut R</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.84.1/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;&amp;Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type rand::seq::SliceRandom::Item">Item</a>&gt;
<span class="where">where R: <a class="trait" href="../trait.Rng.html" title="trait rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span>;
<span class="item-spacer"></span> fn <a href="#tymethod.choose_mut" class="fn">choose_mut</a>&lt;R&gt;(&amp;mut self, rng: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;mut R</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.84.1/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&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">where R: <a class="trait" href="../trait.Rng.html" title="trait rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span>;
<span class="item-spacer"></span> fn <a href="#tymethod.choose_multiple" class="fn">choose_multiple</a>&lt;R&gt;(
&amp;self,
rng: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;mut R</a>,
amount: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.usize.html">usize</a>,
) -&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; <a href="#" class="tooltip" data-notable-ty="SliceChooseIter&lt;&#39;_, Self, Self::Item&gt;"></a>
<span class="where">where R: <a class="trait" href="../trait.Rng.html" title="trait rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span>;
<span class="item-spacer"></span> fn <a href="#tymethod.choose_weighted" class="fn">choose_weighted</a>&lt;R, F, B, X&gt;(
&amp;self,
rng: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;mut R</a>,
weight: F,
) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.84.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&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/enum.WeightedError.html" title="enum rand::distributions::WeightedError">WeightedError</a>&gt;
<span class="where">where R: <a class="trait" href="../trait.Rng.html" title="trait rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
F: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(&amp;Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type rand::seq::SliceRandom::Item">Item</a>) -&gt; B,
B: <a class="trait" href="../distributions/uniform/trait.SampleBorrow.html" title="trait rand::distributions::uniform::SampleBorrow">SampleBorrow</a>&lt;X&gt;,
X: <a class="trait" href="../distributions/uniform/trait.SampleUniform.html" title="trait rand::distributions::uniform::SampleUniform">SampleUniform</a> + for&lt;'a&gt; <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/ops/arith/trait.AddAssign.html" title="trait core::ops::arith::AddAssign">AddAssign</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;'a X</a>&gt; + <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a>&lt;X&gt; + <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> + <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/default/trait.Default.html" title="trait core::default::Default">Default</a></span>;
<span class="item-spacer"></span> fn <a href="#tymethod.choose_weighted_mut" class="fn">choose_weighted_mut</a>&lt;R, F, B, X&gt;(
&amp;mut self,
rng: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;mut R</a>,
weight: F,
) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.84.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&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/enum.WeightedError.html" title="enum rand::distributions::WeightedError">WeightedError</a>&gt;
<span class="where">where R: <a class="trait" href="../trait.Rng.html" title="trait rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
F: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(&amp;Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type rand::seq::SliceRandom::Item">Item</a>) -&gt; B,
B: <a class="trait" href="../distributions/uniform/trait.SampleBorrow.html" title="trait rand::distributions::uniform::SampleBorrow">SampleBorrow</a>&lt;X&gt;,
X: <a class="trait" href="../distributions/uniform/trait.SampleUniform.html" title="trait rand::distributions::uniform::SampleUniform">SampleUniform</a> + for&lt;'a&gt; <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/ops/arith/trait.AddAssign.html" title="trait core::ops::arith::AddAssign">AddAssign</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;'a X</a>&gt; + <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a>&lt;X&gt; + <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> + <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/default/trait.Default.html" title="trait core::default::Default">Default</a></span>;
<span class="item-spacer"></span> fn <a href="#tymethod.choose_multiple_weighted" class="fn">choose_multiple_weighted</a>&lt;R, F, X&gt;(
&amp;self,
rng: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;mut R</a>,
amount: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.usize.html">usize</a>,
weight: F,
) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.84.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&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/enum.WeightedError.html" title="enum rand::distributions::WeightedError">WeightedError</a>&gt;
<span class="where">where R: <a class="trait" href="../trait.Rng.html" title="trait rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
F: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(&amp;Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type rand::seq::SliceRandom::Item">Item</a>) -&gt; X,
X: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.f64.html">f64</a>&gt;</span>;
<span class="item-spacer"></span> fn <a href="#tymethod.shuffle" class="fn">shuffle</a>&lt;R&gt;(&amp;mut self, rng: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;mut R</a>)
<span class="where">where R: <a class="trait" href="../trait.Rng.html" title="trait rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span>;
<span class="item-spacer"></span> fn <a href="#tymethod.partial_shuffle" class="fn">partial_shuffle</a>&lt;R&gt;(
&amp;mut self,
rng: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;mut R</a>,
amount: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.usize.html">usize</a>,
) -&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">where R: <a class="trait" href="../trait.Rng.html" title="trait rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span>;
}</code></pre><details class="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">"Hello, random!"</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">"{}"</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="section-header">Required Associated Types<a href="#required-associated-types" class="anchor">§</a></h2><div class="methods"><details class="toggle" open><summary><section id="associatedtype.Item" class="method"><a class="src 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="section-header">Required Methods<a href="#required-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="tymethod.choose" class="method"><a class="src rightside" href="../../src/rand/seq/mod.rs.html#79-80">Source</a><h4 class="code-header">fn <a href="#tymethod.choose" class="fn">choose</a>&lt;R&gt;(&amp;self, rng: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;mut R</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.84.1/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;&amp;Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type rand::seq::SliceRandom::Item">Item</a>&gt;<div class="where">where
R: <a class="trait" href="../trait.Rng.html" title="trait rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></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 class="doc-anchor" href="#example">§</a>Example</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">"{:?}"</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="toggle method-toggle" open><summary><section id="tymethod.choose_mut" class="method"><a class="src rightside" href="../../src/rand/seq/mod.rs.html#86-87">Source</a><h4 class="code-header">fn <a href="#tymethod.choose_mut" class="fn">choose_mut</a>&lt;R&gt;(&amp;mut self, rng: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;mut R</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.84.1/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;&amp;mut Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type rand::seq::SliceRandom::Item">Item</a>&gt;<div class="where">where
R: <a class="trait" href="../trait.Rng.html" title="trait rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></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="toggle method-toggle" open><summary><section id="tymethod.choose_multiple" class="method"><a class="src rightside" href="../../src/rand/seq/mod.rs.html#115-116">Source</a><h4 class="code-header">fn <a href="#tymethod.choose_multiple" class="fn">choose_multiple</a>&lt;R&gt;(
&amp;self,
rng: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;mut R</a>,
amount: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.usize.html">usize</a>,
) -&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; <a href="#" class="tooltip" data-notable-ty="SliceChooseIter&lt;&#39;_, Self, Self::Item&gt;"></a><div class="where">where
R: <a class="trait" href="../trait.Rng.html" title="trait rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></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="fn rand::seq::index::sample"><code>index::sample</code></a>.</p>
<p>For slices, complexity is the same as <a href="index/fn.sample.html" title="fn rand::seq::index::sample"><code>index::sample</code></a>.</p>
<h5 id="example-1"><a class="doc-anchor" href="#example-1">§</a>Example</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">"Hello, audience!"</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="toggle method-toggle" open><summary><section id="tymethod.choose_weighted" class="method"><a class="src rightside" href="../../src/rand/seq/mod.rs.html#143-154">Source</a><h4 class="code-header">fn <a href="#tymethod.choose_weighted" class="fn">choose_weighted</a>&lt;R, F, B, X&gt;(
&amp;self,
rng: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;mut R</a>,
weight: F,
) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.84.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&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/enum.WeightedError.html" title="enum rand::distributions::WeightedError">WeightedError</a>&gt;<div class="where">where
R: <a class="trait" href="../trait.Rng.html" title="trait rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
F: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(&amp;Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type rand::seq::SliceRandom::Item">Item</a>) -&gt; B,
B: <a class="trait" href="../distributions/uniform/trait.SampleBorrow.html" title="trait rand::distributions::uniform::SampleBorrow">SampleBorrow</a>&lt;X&gt;,
X: <a class="trait" href="../distributions/uniform/trait.SampleUniform.html" title="trait rand::distributions::uniform::SampleUniform">SampleUniform</a> + for&lt;'a&gt; <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/ops/arith/trait.AddAssign.html" title="trait core::ops::arith::AddAssign">AddAssign</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;'a X</a>&gt; + <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a>&lt;X&gt; + <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> + <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/default/trait.Default.html" title="trait core::default::Default">Default</a>,</div></h4></section></summary><div class="docblock"><p>Similar to <a href="trait.SliceRandom.html#tymethod.choose" title="method rand::seq::SliceRandom::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" title="method rand::seq::SliceRandom::choose_weighted_mut"><code>choose_weighted_mut</code></a>, <a href="../distributions/weighted/index.html" title="mod rand::distributions::weighted"><code>distributions::weighted</code></a>.</p>
<h5 id="example-2"><a class="doc-anchor" href="#example-2">§</a>Example</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">'a'</span>, <span class="number">2</span>), (<span class="string">'b'</span>, <span class="number">1</span>), (<span class="string">'c'</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 'a', 25% chance to print 'b', 25% chance to print 'c'
</span><span class="macro">println!</span>(<span class="string">"{:?}"</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="toggle method-toggle" open><summary><section id="tymethod.choose_weighted_mut" class="method"><a class="src rightside" href="../../src/rand/seq/mod.rs.html#171-182">Source</a><h4 class="code-header">fn <a href="#tymethod.choose_weighted_mut" class="fn">choose_weighted_mut</a>&lt;R, F, B, X&gt;(
&amp;mut self,
rng: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;mut R</a>,
weight: F,
) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.84.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&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/enum.WeightedError.html" title="enum rand::distributions::WeightedError">WeightedError</a>&gt;<div class="where">where
R: <a class="trait" href="../trait.Rng.html" title="trait rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
F: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(&amp;Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type rand::seq::SliceRandom::Item">Item</a>) -&gt; B,
B: <a class="trait" href="../distributions/uniform/trait.SampleBorrow.html" title="trait rand::distributions::uniform::SampleBorrow">SampleBorrow</a>&lt;X&gt;,
X: <a class="trait" href="../distributions/uniform/trait.SampleUniform.html" title="trait rand::distributions::uniform::SampleUniform">SampleUniform</a> + for&lt;'a&gt; <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/ops/arith/trait.AddAssign.html" title="trait core::ops::arith::AddAssign">AddAssign</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;'a X</a>&gt; + <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a>&lt;X&gt; + <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> + <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/default/trait.Default.html" title="trait core::default::Default">Default</a>,</div></h4></section></summary><div class="docblock"><p>Similar to <a href="trait.SliceRandom.html#tymethod.choose_mut" title="method rand::seq::SliceRandom::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" title="method rand::seq::SliceRandom::choose_weighted"><code>choose_weighted</code></a>, <a href="../distributions/weighted/index.html" title="mod rand::distributions::weighted"><code>distributions::weighted</code></a>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.choose_multiple_weighted" class="method"><a class="src rightside" href="../../src/rand/seq/mod.rs.html#220-226">Source</a><h4 class="code-header">fn <a href="#tymethod.choose_multiple_weighted" class="fn">choose_multiple_weighted</a>&lt;R, F, X&gt;(
&amp;self,
rng: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;mut R</a>,
amount: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.usize.html">usize</a>,
weight: F,
) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.84.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&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/enum.WeightedError.html" title="enum rand::distributions::WeightedError">WeightedError</a>&gt;<div class="where">where
R: <a class="trait" href="../trait.Rng.html" title="trait rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
F: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(&amp;Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type rand::seq::SliceRandom::Item">Item</a>) -&gt; X,
X: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.f64.html">f64</a>&gt;,</div></h4></section></summary><div class="docblock"><p>Similar to <a href="trait.SliceRandom.html#tymethod.choose_multiple" title="method rand::seq::SliceRandom::choose_multiple"><code>choose_multiple</code></a>, but where the likelihood of each elements
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 class="doc-anchor" href="#example-3">§</a>Example</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">'a'</span>, <span class="number">2</span>), (<span class="string">'b'</span>, <span class="number">1</span>), (<span class="string">'c'</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 `['a', 'b']` in some order.
// (50% * 50%) + (25% * 67%) = 41.7% chance that the output is `['a', 'c']` in some order.
// (25% * 33%) + (25% * 33%) = 16.6% chance that the output is `['b', 'c']` in some order.
</span><span class="macro">println!</span>(<span class="string">"{:?}"</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="toggle method-toggle" open><summary><section id="tymethod.shuffle" class="method"><a class="src rightside" href="../../src/rand/seq/mod.rs.html#244-245">Source</a><h4 class="code-header">fn <a href="#tymethod.shuffle" class="fn">shuffle</a>&lt;R&gt;(&amp;mut self, rng: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;mut R</a>)<div class="where">where
R: <a class="trait" href="../trait.Rng.html" title="trait rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></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 class="doc-anchor" href="#example-4">§</a>Example</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">"Unshuffled: {:?}"</span>, y);
y.shuffle(<span class="kw-2">&amp;mut </span>rng);
<span class="macro">println!</span>(<span class="string">"Shuffled: {:?}"</span>, y);</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.partial_shuffle" class="method"><a class="src rightside" href="../../src/rand/seq/mod.rs.html#264-267">Source</a><h4 class="code-header">fn <a href="#tymethod.partial_shuffle" class="fn">partial_shuffle</a>&lt;R&gt;(
&amp;mut self,
rng: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;mut R</a>,
amount: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.usize.html">usize</a>,
) -&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>])<div class="where">where
R: <a class="trait" href="../trait.Rng.html" title="trait rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></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="dyn-compatibility" class="section-header">Dyn Compatibility<a href="#dyn-compatibility" class="anchor">§</a></h2><div class="dyn-compatibility-info"><p>This trait is <b>not</b> <a href="https://doc.rust-lang.org/1.84.1/reference/items/traits.html#object-safety">dyn compatible</a>.</p><p><i>In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.</i></p></div><h2 id="foreign-impls" class="section-header">Implementations on Foreign Types<a href="#foreign-impls" class="anchor">§</a></h2><details class="toggle implementors-toggle"><summary><section id="impl-SliceRandom-for-%5BT%5D" class="impl"><a class="src 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 <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.slice.html">[T]</a></h3></section></summary><div class="impl-items"><section id="associatedtype.Item-1" class="associatedtype trait-impl"><a class="src rightside" href="../../src/rand/seq/mod.rs.html#493">Source</a><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"><a class="src 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="fn">choose</a>&lt;R&gt;(&amp;self, rng: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;mut R</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.84.1/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;&amp;Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type rand::seq::SliceRandom::Item">Item</a>&gt;<div class="where">where
R: <a class="trait" href="../trait.Rng.html" title="trait rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section><section id="method.choose_mut" class="method trait-impl"><a class="src 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="fn">choose_mut</a>&lt;R&gt;(&amp;mut self, rng: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;mut R</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.84.1/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;&amp;mut Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type rand::seq::SliceRandom::Item">Item</a>&gt;<div class="where">where
R: <a class="trait" href="../trait.Rng.html" title="trait rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section><section id="method.choose_multiple" class="method trait-impl"><a class="src 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="fn">choose_multiple</a>&lt;R&gt;(
&amp;self,
rng: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;mut R</a>,
amount: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.usize.html">usize</a>,
) -&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; <a href="#" class="tooltip" data-notable-ty="SliceChooseIter&lt;&#39;_, Self, Self::Item&gt;"></a><div class="where">where
R: <a class="trait" href="../trait.Rng.html" title="trait rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section><section id="method.choose_weighted" class="method trait-impl"><a class="src 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="fn">choose_weighted</a>&lt;R, F, B, X&gt;(
&amp;self,
rng: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;mut R</a>,
weight: F,
) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.84.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&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/enum.WeightedError.html" title="enum rand::distributions::WeightedError">WeightedError</a>&gt;<div class="where">where
R: <a class="trait" href="../trait.Rng.html" title="trait rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
F: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(&amp;Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type rand::seq::SliceRandom::Item">Item</a>) -&gt; B,
B: <a class="trait" href="../distributions/uniform/trait.SampleBorrow.html" title="trait rand::distributions::uniform::SampleBorrow">SampleBorrow</a>&lt;X&gt;,
X: <a class="trait" href="../distributions/uniform/trait.SampleUniform.html" title="trait rand::distributions::uniform::SampleUniform">SampleUniform</a> + for&lt;'a&gt; <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/ops/arith/trait.AddAssign.html" title="trait core::ops::arith::AddAssign">AddAssign</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;'a X</a>&gt; + <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a>&lt;X&gt; + <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> + <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/default/trait.Default.html" title="trait core::default::Default">Default</a>,</div></h4></section><section id="method.choose_weighted_mut" class="method trait-impl"><a class="src 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="fn">choose_weighted_mut</a>&lt;R, F, B, X&gt;(
&amp;mut self,
rng: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;mut R</a>,
weight: F,
) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.84.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&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/enum.WeightedError.html" title="enum rand::distributions::WeightedError">WeightedError</a>&gt;<div class="where">where
R: <a class="trait" href="../trait.Rng.html" title="trait rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
F: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(&amp;Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type rand::seq::SliceRandom::Item">Item</a>) -&gt; B,
B: <a class="trait" href="../distributions/uniform/trait.SampleBorrow.html" title="trait rand::distributions::uniform::SampleBorrow">SampleBorrow</a>&lt;X&gt;,
X: <a class="trait" href="../distributions/uniform/trait.SampleUniform.html" title="trait rand::distributions::uniform::SampleUniform">SampleUniform</a> + for&lt;'a&gt; <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/ops/arith/trait.AddAssign.html" title="trait core::ops::arith::AddAssign">AddAssign</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;'a X</a>&gt; + <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a>&lt;X&gt; + <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> + <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/default/trait.Default.html" title="trait core::default::Default">Default</a>,</div></h4></section><section id="method.choose_multiple_weighted" class="method trait-impl"><a class="src 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="fn">choose_multiple_weighted</a>&lt;R, F, X&gt;(
&amp;self,
rng: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;mut R</a>,
amount: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.usize.html">usize</a>,
weight: F,
) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.84.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&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/enum.WeightedError.html" title="enum rand::distributions::WeightedError">WeightedError</a>&gt;<div class="where">where
R: <a class="trait" href="../trait.Rng.html" title="trait rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
F: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(&amp;Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type rand::seq::SliceRandom::Item">Item</a>) -&gt; X,
X: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.f64.html">f64</a>&gt;,</div></h4></section><section id="method.shuffle" class="method trait-impl"><a class="src 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="fn">shuffle</a>&lt;R&gt;(&amp;mut self, rng: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;mut R</a>)<div class="where">where
R: <a class="trait" href="../trait.Rng.html" title="trait rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section><section id="method.partial_shuffle" class="method trait-impl"><a class="src 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="fn">partial_shuffle</a>&lt;R&gt;(
&amp;mut self,
rng: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;mut R</a>,
amount: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.usize.html">usize</a>,
) -&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>])<div class="where">where
R: <a class="trait" href="../trait.Rng.html" title="trait rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></div></details><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"></div><script src="../../trait.impl/rand/seq/trait.SliceRandom.js" data-ignore-extern-crates="std" async></script><script type="text/json" id="notable-traits-data">{"SliceChooseIter<'_, Self, Self::Item>":"<h3>Notable traits for <code><a class=\"struct\" href=\"struct.SliceChooseIter.html\" title=\"struct rand::seq::SliceChooseIter\">SliceChooseIter</a>&lt;'a, S, T&gt;</code></h3><pre><code><div class=\"where\">impl&lt;'a, S: <a class=\"trait\" href=\"https://doc.rust-lang.org/1.84.1/core/ops/index/trait.Index.html\" title=\"trait core::ops::index::Index\">Index</a>&lt;<a class=\"primitive\" href=\"https://doc.rust-lang.org/1.84.1/std/primitive.usize.html\">usize</a>, Output = T&gt; + ?<a class=\"trait\" href=\"https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html\" title=\"trait core::marker::Sized\">Sized</a> + 'a, T: 'a&gt; <a class=\"trait\" href=\"https://doc.rust-lang.org/1.84.1/core/iter/traits/iterator/trait.Iterator.html\" title=\"trait core::iter::traits::iterator::Iterator\">Iterator</a> for <a class=\"struct\" href=\"struct.SliceChooseIter.html\" title=\"struct rand::seq::SliceChooseIter\">SliceChooseIter</a>&lt;'a, S, T&gt;</div><div class=\"where\"> type <a href=\"https://doc.rust-lang.org/1.84.1/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item\" class=\"associatedtype\">Item</a> = <a class=\"primitive\" href=\"https://doc.rust-lang.org/1.84.1/std/primitive.reference.html\">&amp;'a T</a>;</div>"}</script></section></div></main></body></html>