Files
GopherGate/target/doc/rand/seq/trait.IndexedMutRandom.html
2026-02-26 12:00:21 -05:00

40 lines
13 KiB
HTML

<!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 indexable lists, providing random sampling methods."><title>IndexedMutRandom in rand::seq - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.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"href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-ca0dd0c4.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.93.1 (01f6ddf75 2026-02-11) (Arch Linux rust 1:1.93.1-1)" data-channel="1.93.1" data-search-js="search-9e2438ea.js" data-stringdex-js="stringdex-a3946164.js" data-settings-js="settings-c38705f0.js" ><script src="../../static.files/storage-e2aeef58.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-a410ff4d.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-263c88ec.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]--><rustdoc-topbar><h2><a href="#">IndexedMutRandom</a></h2></rustdoc-topbar><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.9.2</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Indexed<wbr>MutRandom</a></h2><h3><a href="#provided-methods">Provided Methods</a></h3><ul class="block"><li><a href="#method.choose_mut" title="choose_mut">choose_mut</a></li><li><a href="#method.choose_weighted_mut" title="choose_weighted_mut">choose_weighted_mut</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" title="Drag to resize sidebar"></div><main><div class="width-limiter"><section id="main-content" class="content"><div class="main-heading"><div class="rustdoc-breadcrumbs"><a href="../index.html">rand</a>::<wbr><a href="index.html">seq</a></div><h1>Trait <span class="trait">Indexed<wbr>MutRandom</span>&nbsp;<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/slice.rs.html#242-296">Source</a> </span></div><pre class="rust item-decl"><code>pub trait IndexedMutRandom: <a class="trait" href="trait.IndexedRandom.html" title="trait rand::seq::IndexedRandom">IndexedRandom</a> + <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/ops/index/trait.IndexMut.html" title="trait core::ops::index::IndexMut">IndexMut</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.usize.html">usize</a>&gt; {
// Provided methods
fn <a href="#method.choose_mut" class="fn">choose_mut</a>&lt;R&gt;(&amp;mut self, rng: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.reference.html">&amp;mut R</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.93.1/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;&amp;mut Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.93.1/core/ops/index/trait.Index.html#associatedtype.Output" title="type core::ops::index::Index::Output">Output</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.93.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
<span class="item-spacer"></span> fn <a href="#method.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.93.1/std/primitive.reference.html">&amp;mut R</a>,
weight: F,
) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.93.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;&amp;mut Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.93.1/core/ops/index/trait.Index.html#associatedtype.Output" title="type core::ops::index::Index::Output">Output</a>, <a class="enum" href="../distr/weighted/enum.Error.html" title="enum rand::distr::weighted::Error">WeightError</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.93.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
F: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(&amp;Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.93.1/core/ops/index/trait.Index.html#associatedtype.Output" title="type core::ops::index::Index::Output">Output</a>) -&gt; B,
B: <a class="trait" href="../distr/uniform/trait.SampleBorrow.html" title="trait rand::distr::uniform::SampleBorrow">SampleBorrow</a>&lt;X&gt;,
X: <a class="trait" href="../distr/uniform/trait.SampleUniform.html" title="trait rand::distr::uniform::SampleUniform">SampleUniform</a> + <a class="trait" href="../distr/weighted/trait.Weight.html" title="trait rand::distr::weighted::Weight">Weight</a> + <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a>&lt;X&gt;</span> { ... }
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Extension trait on indexable lists, providing random sampling methods.</p>
<p>This trait is implemented automatically for every type implementing
<a href="trait.IndexedRandom.html" title="trait rand::seq::IndexedRandom"><code>IndexedRandom</code></a> and <a href="https://doc.rust-lang.org/1.93.1/core/ops/index/trait.IndexMut.html" title="trait core::ops::index::IndexMut"><code>std::ops::IndexMut&lt;usize&gt;</code></a>.</p>
</div></details><h2 id="provided-methods" class="section-header">Provided Methods<a href="#provided-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="method.choose_mut" class="method"><a class="src rightside" href="../../src/rand/seq/slice.rs.html#249-259">Source</a><h4 class="code-header">fn <a href="#method.choose_mut" class="fn">choose_mut</a>&lt;R&gt;(&amp;mut self, rng: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.reference.html">&amp;mut R</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.93.1/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;&amp;mut Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.93.1/core/ops/index/trait.Index.html#associatedtype.Output" title="type core::ops::index::Index::Output">Output</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.93.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><div class="docblock"><p>Uniformly sample one element (mut)</p>
<p>Returns a mutable reference to one uniformly-sampled 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="method.choose_weighted_mut" class="method"><a class="src rightside" href="../../src/rand/seq/slice.rs.html#280-295">Source</a><h4 class="code-header">fn <a href="#method.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.93.1/std/primitive.reference.html">&amp;mut R</a>,
weight: F,
) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.93.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;&amp;mut Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.93.1/core/ops/index/trait.Index.html#associatedtype.Output" title="type core::ops::index::Index::Output">Output</a>, <a class="enum" href="../distr/weighted/enum.Error.html" title="enum rand::distr::weighted::Error">WeightError</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.93.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
F: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(&amp;Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.93.1/core/ops/index/trait.Index.html#associatedtype.Output" title="type core::ops::index::Index::Output">Output</a>) -&gt; B,
B: <a class="trait" href="../distr/uniform/trait.SampleBorrow.html" title="trait rand::distr::uniform::SampleBorrow">SampleBorrow</a>&lt;X&gt;,
X: <a class="trait" href="../distr/uniform/trait.SampleUniform.html" title="trait rand::distr::uniform::SampleUniform">SampleUniform</a> + <a class="trait" href="../distr/weighted/trait.Weight.html" title="trait rand::distr::weighted::Weight">Weight</a> + <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a>&lt;X&gt;,</div></h4></section></summary><div class="docblock"><p>Biased sampling for one element (mut)</p>
<p>Returns a mutable reference to one element of the slice, sampled according
to the provided weights. Returns <code>None</code> only if the slice is empty.</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>.
For more information about the underlying algorithm,
see the <a href="../distr/weighted/struct.WeightedIndex.html" title="struct rand::distr::weighted::WeightedIndex"><code>WeightedIndex</code></a> distribution.</p>
<p>See also <a href="trait.IndexedRandom.html#method.choose_weighted" title="method rand::seq::IndexedRandom::choose_weighted"><code>choose_weighted</code></a>.</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.93.1/reference/items/traits.html#dyn-compatibility">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="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"><section id="impl-IndexedMutRandom-for-IR" class="impl"><a class="src rightside" href="../../src/rand/seq/slice.rs.html#370">Source</a><a href="#impl-IndexedMutRandom-for-IR" class="anchor">§</a><h3 class="code-header">impl&lt;IR: <a class="trait" href="trait.IndexedRandom.html" title="trait rand::seq::IndexedRandom">IndexedRandom</a> + <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/ops/index/trait.IndexMut.html" title="trait core::ops::index::IndexMut">IndexMut</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.usize.html">usize</a>&gt; + ?<a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>&gt; <a class="trait" href="trait.IndexedMutRandom.html" title="trait rand::seq::IndexedMutRandom">IndexedMutRandom</a> for IR</h3></section></div><script src="../../trait.impl/rand/seq/slice/trait.IndexedMutRandom.js" async></script></section></div></main></body></html>