1 <!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Extension trait on slices, providing random mutation and sampling methods."><title>SliceRandom in bdk_chain::bitcoin::secp256k1::rand::seq - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-46f98efaafac5295.ttf.woff2,FiraSans-Regular-018c141bf0843ffd.woff2,FiraSans-Medium-8f9a781e4970d388.woff2,SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2,SourceCodePro-Semibold-d899c5a5c4aeb14a.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-76eba96aa4d2e634.css"><link rel="stylesheet" href="../../../../../static.files/rustdoc-dd39b87e5fcfba68.css"><meta name="rustdoc-vars" data-root-path="../../../../../" data-static-root-path="../../../../../static.files/" data-current-crate="bdk_chain" data-themes="" data-resource-suffix="" data-rustdoc-version="1.80.0-nightly (78a775127 2024-05-11)" data-channel="nightly" data-search-js="search-d52510db62a78183.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="../../../../../static.files/storage-118b08c4c78b968e.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../../../../static.files/main-20a3ad099b048cf2.js"></script><noscript><link rel="stylesheet" href="../../../../../static.files/noscript-df360f571f6edeae.css"></noscript><link rel="alternate icon" type="image/png" href="../../../../../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../../../../../static.files/favicon-2c020d218678b618.svg"></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="../../../../../bdk_chain/index.html"><img src="https://github.com/bitcoindevkit/bdk/raw/master/static/bdk.png" alt=""></a></nav><nav class="sidebar"><div class="sidebar-crate"><a class="logo-container" href="../../../../../bdk_chain/index.html"><img src="https://github.com/bitcoindevkit/bdk/raw/master/static/bdk.png" alt="logo"></a><h2><a href="../../../../../bdk_chain/index.html">bdk_chain</a><span class="version">0.20.0</span></h2></div><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="#object-safety">Object Safety</a></h3><h3><a href="#implementors">Implementors</a></h3></section><h2><a href="index.html">In bdk_chain::bitcoin::secp256k1::rand::seq</a></h2></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"><h1>Trait <a href="../../../../index.html">bdk_chain</a>::<wbr><a href="../../../index.html">bitcoin</a>::<wbr><a href="../../index.html">secp256k1</a>::<wbr><a href="../index.html">rand</a>::<wbr><a href="index.html">seq</a>::<wbr><a class="trait" href="#">SliceRandom</a><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><span class="out-of-band"><a class="src" href="https://rust-random.github.io/rand/src/rand/seq/mod.rs.html#59">source</a> · <button id="toggle-all-docs" title="collapse all docs">[<span>−</span>]</button></span></div><pre class="rust item-decl"><code>pub trait SliceRandom {
2 type <a href="#associatedtype.Item" class="associatedtype">Item</a>;
5 fn <a href="#tymethod.choose" class="fn">choose</a><R>(&self, rng: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut R</a>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><&Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom::Item">Item</a>>
6 <span class="where">where R: <a class="trait" href="../trait.Rng.html" title="trait bdk_chain::bitcoin::secp256k1::rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span>;
7 <span class="item-spacer"></span> fn <a href="#tymethod.choose_mut" class="fn">choose_mut</a><R>(&mut self, rng: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut R</a>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><&mut Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom::Item">Item</a>>
8 <span class="where">where R: <a class="trait" href="../trait.Rng.html" title="trait bdk_chain::bitcoin::secp256k1::rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span>;
9 <span class="item-spacer"></span> fn <a href="#tymethod.choose_multiple" class="fn">choose_multiple</a><R>(
11 rng: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut R</a>,
12 amount: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>
13 ) -> <a class="struct" href="struct.SliceChooseIter.html" title="struct bdk_chain::bitcoin::secp256k1::rand::seq::SliceChooseIter">SliceChooseIter</a><'_, Self, Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom::Item">Item</a>> <a href="#" class="tooltip" data-notable-ty="SliceChooseIter<'_, Self, Self::Item>">ⓘ</a>
14 <span class="where">where R: <a class="trait" href="../trait.Rng.html" title="trait bdk_chain::bitcoin::secp256k1::rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span>;
15 <span class="item-spacer"></span> fn <a href="#tymethod.choose_weighted" class="fn">choose_weighted</a><R, F, B, X>(
17 rng: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut R</a>,
19 ) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><&Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom::Item">Item</a>, <a class="enum" href="../distributions/enum.WeightedError.html" title="enum bdk_chain::bitcoin::secp256k1::rand::distributions::WeightedError">WeightedError</a>>
20 <span class="where">where R: <a class="trait" href="../trait.Rng.html" title="trait bdk_chain::bitcoin::secp256k1::rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
21 F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(&Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom::Item">Item</a>) -> B,
22 B: <a class="trait" href="../distributions/uniform/trait.SampleBorrow.html" title="trait bdk_chain::bitcoin::secp256k1::rand::distributions::uniform::SampleBorrow">SampleBorrow</a><X>,
23 X: <a class="trait" href="../distributions/uniform/trait.SampleUniform.html" title="trait bdk_chain::bitcoin::secp256k1::rand::distributions::uniform::SampleUniform">SampleUniform</a> + for<'a> <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/arith/trait.AddAssign.html" title="trait core::ops::arith::AddAssign">AddAssign</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a X</a>> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/default/trait.Default.html" title="trait core::default::Default">Default</a></span>;
24 <span class="item-spacer"></span> fn <a href="#tymethod.choose_weighted_mut" class="fn">choose_weighted_mut</a><R, F, B, X>(
26 rng: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut R</a>,
28 ) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><&mut Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom::Item">Item</a>, <a class="enum" href="../distributions/enum.WeightedError.html" title="enum bdk_chain::bitcoin::secp256k1::rand::distributions::WeightedError">WeightedError</a>>
29 <span class="where">where R: <a class="trait" href="../trait.Rng.html" title="trait bdk_chain::bitcoin::secp256k1::rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
30 F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(&Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom::Item">Item</a>) -> B,
31 B: <a class="trait" href="../distributions/uniform/trait.SampleBorrow.html" title="trait bdk_chain::bitcoin::secp256k1::rand::distributions::uniform::SampleBorrow">SampleBorrow</a><X>,
32 X: <a class="trait" href="../distributions/uniform/trait.SampleUniform.html" title="trait bdk_chain::bitcoin::secp256k1::rand::distributions::uniform::SampleUniform">SampleUniform</a> + for<'a> <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/arith/trait.AddAssign.html" title="trait core::ops::arith::AddAssign">AddAssign</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a X</a>> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/default/trait.Default.html" title="trait core::default::Default">Default</a></span>;
33 <span class="item-spacer"></span> fn <a href="#tymethod.choose_multiple_weighted" class="fn">choose_multiple_weighted</a><R, F, X>(
35 rng: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut R</a>,
36 amount: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>,
38 ) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="struct.SliceChooseIter.html" title="struct bdk_chain::bitcoin::secp256k1::rand::seq::SliceChooseIter">SliceChooseIter</a><'_, Self, Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom::Item">Item</a>>, <a class="enum" href="../distributions/enum.WeightedError.html" title="enum bdk_chain::bitcoin::secp256k1::rand::distributions::WeightedError">WeightedError</a>>
39 <span class="where">where R: <a class="trait" href="../trait.Rng.html" title="trait bdk_chain::bitcoin::secp256k1::rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
40 F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(&Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom::Item">Item</a>) -> X,
41 X: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.f64.html">f64</a>></span>;
42 <span class="item-spacer"></span> fn <a href="#tymethod.shuffle" class="fn">shuffle</a><R>(&mut self, rng: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut R</a>)
43 <span class="where">where R: <a class="trait" href="../trait.Rng.html" title="trait bdk_chain::bitcoin::secp256k1::rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span>;
44 <span class="item-spacer"></span> fn <a href="#tymethod.partial_shuffle" class="fn">partial_shuffle</a><R>(
46 rng: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut R</a>,
47 amount: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>
48 ) -> (&mut [Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom::Item">Item</a>], &mut [Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom::Item">Item</a>])
49 <span class="where">where R: <a class="trait" href="../trait.Rng.html" title="trait bdk_chain::bitcoin::secp256k1::rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span>;
50 }</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>
51 <p>This trait is implemented on all <code>[T]</code> slice types, providing several
52 methods for choosing and shuffling elements. You must <code>use</code> this trait:</p>
54 <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>rand::seq::SliceRandom;
56 <span class="kw">let </span><span class="kw-2">mut </span>rng = rand::thread_rng();
57 <span class="kw">let </span><span class="kw-2">mut </span>bytes = <span class="string">"Hello, random!"</span>.to_string().into_bytes();
58 bytes.shuffle(<span class="kw-2">&mut </span>rng);
59 <span class="kw">let </span>str = String::from_utf8(bytes).unwrap();
60 <span class="macro">println!</span>(<span class="string">"{}"</span>, str);</code></pre></div>
61 <p>Example output (non-deterministic):</p>
62 <div class="example-wrap"><pre class="language-none"><code>l,nmroHado !le
63 </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="https://rust-random.github.io/rand/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>
64 </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="https://rust-random.github.io/rand/src/rand/seq/mod.rs.html#79-80">source</a><h4 class="code-header">fn <a href="#tymethod.choose" class="fn">choose</a><R>(&self, rng: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut R</a>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><&Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom::Item">Item</a>><div class="where">where
65 R: <a class="trait" href="../trait.Rng.html" title="trait bdk_chain::bitcoin::secp256k1::rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/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
67 <p>For slices, complexity is <code>O(1)</code>.</p>
68 <h5 id="example"><a class="doc-anchor" href="#example">§</a>Example</h5>
69 <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>rand::thread_rng;
70 <span class="kw">use </span>rand::seq::SliceRandom;
72 <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>];
73 <span class="kw">let </span><span class="kw-2">mut </span>rng = thread_rng();
74 <span class="macro">println!</span>(<span class="string">"{:?}"</span>, choices.choose(<span class="kw-2">&mut </span>rng));
75 <span class="macro">assert_eq!</span>(choices[..<span class="number">0</span>].choose(<span class="kw-2">&mut </span>rng), <span class="prelude-val">None</span>);</code></pre></div>
76 </div></details><details class="toggle method-toggle" open><summary><section id="tymethod.choose_mut" class="method"><a class="src rightside" href="https://rust-random.github.io/rand/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><R>(&mut self, rng: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut R</a>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><&mut Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom::Item">Item</a>><div class="where">where
77 R: <a class="trait" href="../trait.Rng.html" title="trait bdk_chain::bitcoin::secp256k1::rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/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
78 <code>None</code> if the slice is empty.</p>
79 <p>For slices, complexity is <code>O(1)</code>.</p>
80 </div></details><details class="toggle method-toggle" open><summary><section id="tymethod.choose_multiple" class="method"><a class="src rightside" href="https://rust-random.github.io/rand/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><R>(
82 rng: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut R</a>,
83 amount: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>
84 ) -> <a class="struct" href="struct.SliceChooseIter.html" title="struct bdk_chain::bitcoin::secp256k1::rand::seq::SliceChooseIter">SliceChooseIter</a><'_, Self, Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom::Item">Item</a>> <a href="#" class="tooltip" data-notable-ty="SliceChooseIter<'_, Self, Self::Item>">ⓘ</a><div class="where">where
85 R: <a class="trait" href="../trait.Rng.html" title="trait bdk_chain::bitcoin::secp256k1::rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/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,
86 and in random order. The returned iterator is appropriate both for
87 collection into a <code>Vec</code> and filling an existing buffer (see example).</p>
88 <p>In case this API is not sufficiently flexible, use <a href="index/fn.sample.html" title="fn bdk_chain::bitcoin::secp256k1::rand::seq::index::sample"><code>index::sample</code></a>.</p>
89 <p>For slices, complexity is the same as <a href="index/fn.sample.html" title="fn bdk_chain::bitcoin::secp256k1::rand::seq::index::sample"><code>index::sample</code></a>.</p>
90 <h5 id="example-1"><a class="doc-anchor" href="#example-1">§</a>Example</h5>
91 <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>rand::seq::SliceRandom;
93 <span class="kw">let </span><span class="kw-2">mut </span>rng = <span class="kw-2">&mut </span>rand::thread_rng();
94 <span class="kw">let </span>sample = <span class="string">"Hello, audience!"</span>.as_bytes();
96 <span class="comment">// collect the results into a vector:
97 </span><span class="kw">let </span>v: Vec<u8> = sample.choose_multiple(<span class="kw-2">&mut </span>rng, <span class="number">3</span>).cloned().collect();
99 <span class="comment">// store in a buffer:
100 </span><span class="kw">let </span><span class="kw-2">mut </span>buf = [<span class="number">0u8</span>; <span class="number">5</span>];
101 <span class="kw">for </span>(b, slot) <span class="kw">in </span>sample.choose_multiple(<span class="kw-2">&mut </span>rng, buf.len()).zip(buf.iter_mut()) {
102 <span class="kw-2">*</span>slot = <span class="kw-2">*</span>b;
104 </div></details><details class="toggle method-toggle" open><summary><section id="tymethod.choose_weighted" class="method"><a class="src rightside" href="https://rust-random.github.io/rand/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><R, F, B, X>(
106 rng: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut R</a>,
108 ) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><&Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom::Item">Item</a>, <a class="enum" href="../distributions/enum.WeightedError.html" title="enum bdk_chain::bitcoin::secp256k1::rand::distributions::WeightedError">WeightedError</a>><div class="where">where
109 R: <a class="trait" href="../trait.Rng.html" title="trait bdk_chain::bitcoin::secp256k1::rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
110 F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(&Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom::Item">Item</a>) -> B,
111 B: <a class="trait" href="../distributions/uniform/trait.SampleBorrow.html" title="trait bdk_chain::bitcoin::secp256k1::rand::distributions::uniform::SampleBorrow">SampleBorrow</a><X>,
112 X: <a class="trait" href="../distributions/uniform/trait.SampleUniform.html" title="trait bdk_chain::bitcoin::secp256k1::rand::distributions::uniform::SampleUniform">SampleUniform</a> + for<'a> <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/arith/trait.AddAssign.html" title="trait core::ops::arith::AddAssign">AddAssign</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a X</a>> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/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 bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom::choose"><code>choose</code></a>, but where the likelihood of each outcome may be
114 <p>The specified function <code>weight</code> maps each item <code>x</code> to a relative
115 likelihood <code>weight(x)</code>. The probability of each item being selected is
116 therefore <code>weight(x) / s</code>, where <code>s</code> is the sum of all <code>weight(x)</code>.</p>
117 <p>For slices of length <code>n</code>, complexity is <code>O(n)</code>.
118 See also <a href="trait.SliceRandom.html#tymethod.choose_weighted_mut" title="method bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom::choose_weighted_mut"><code>choose_weighted_mut</code></a>, <a href="../distributions/weighted/index.html" title="mod bdk_chain::bitcoin::secp256k1::rand::distributions::weighted"><code>distributions::weighted</code></a>.</p>
119 <h5 id="example-2"><a class="doc-anchor" href="#example-2">§</a>Example</h5>
120 <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>rand::prelude::<span class="kw-2">*</span>;
122 <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>)];
123 <span class="kw">let </span><span class="kw-2">mut </span>rng = thread_rng();
124 <span class="comment">// 50% chance to print 'a', 25% chance to print 'b', 25% chance to print 'c'
125 </span><span class="macro">println!</span>(<span class="string">"{:?}"</span>, choices.choose_weighted(<span class="kw-2">&mut </span>rng, |item| item.<span class="number">1</span>).unwrap().<span class="number">0</span>);</code></pre></div>
126 </div></details><details class="toggle method-toggle" open><summary><section id="tymethod.choose_weighted_mut" class="method"><a class="src rightside" href="https://rust-random.github.io/rand/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><R, F, B, X>(
128 rng: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut R</a>,
130 ) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><&mut Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom::Item">Item</a>, <a class="enum" href="../distributions/enum.WeightedError.html" title="enum bdk_chain::bitcoin::secp256k1::rand::distributions::WeightedError">WeightedError</a>><div class="where">where
131 R: <a class="trait" href="../trait.Rng.html" title="trait bdk_chain::bitcoin::secp256k1::rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
132 F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(&Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom::Item">Item</a>) -> B,
133 B: <a class="trait" href="../distributions/uniform/trait.SampleBorrow.html" title="trait bdk_chain::bitcoin::secp256k1::rand::distributions::uniform::SampleBorrow">SampleBorrow</a><X>,
134 X: <a class="trait" href="../distributions/uniform/trait.SampleUniform.html" title="trait bdk_chain::bitcoin::secp256k1::rand::distributions::uniform::SampleUniform">SampleUniform</a> + for<'a> <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/arith/trait.AddAssign.html" title="trait core::ops::arith::AddAssign">AddAssign</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a X</a>> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/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 bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom::choose_mut"><code>choose_mut</code></a>, but where the likelihood of each outcome may
136 <p>The specified function <code>weight</code> maps each item <code>x</code> to a relative
137 likelihood <code>weight(x)</code>. The probability of each item being selected is
138 therefore <code>weight(x) / s</code>, where <code>s</code> is the sum of all <code>weight(x)</code>.</p>
139 <p>For slices of length <code>n</code>, complexity is <code>O(n)</code>.
140 See also <a href="trait.SliceRandom.html#tymethod.choose_weighted" title="method bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom::choose_weighted"><code>choose_weighted</code></a>, <a href="../distributions/weighted/index.html" title="mod bdk_chain::bitcoin::secp256k1::rand::distributions::weighted"><code>distributions::weighted</code></a>.</p>
141 </div></details><details class="toggle method-toggle" open><summary><section id="tymethod.choose_multiple_weighted" class="method"><a class="src rightside" href="https://rust-random.github.io/rand/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><R, F, X>(
143 rng: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut R</a>,
144 amount: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>,
146 ) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="struct.SliceChooseIter.html" title="struct bdk_chain::bitcoin::secp256k1::rand::seq::SliceChooseIter">SliceChooseIter</a><'_, Self, Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom::Item">Item</a>>, <a class="enum" href="../distributions/enum.WeightedError.html" title="enum bdk_chain::bitcoin::secp256k1::rand::distributions::WeightedError">WeightedError</a>><div class="where">where
147 R: <a class="trait" href="../trait.Rng.html" title="trait bdk_chain::bitcoin::secp256k1::rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
148 F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(&Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom::Item">Item</a>) -> X,
149 X: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.f64.html">f64</a>>,</div></h4></section></summary><div class="docblock"><p>Similar to <a href="trait.SliceRandom.html#tymethod.choose_multiple" title="method bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom::choose_multiple"><code>choose_multiple</code></a>, but where the likelihood of each element’s
150 inclusion in the output may be specified. The elements are returned in an
151 arbitrary, unspecified order.</p>
152 <p>The specified function <code>weight</code> maps each item <code>x</code> to a relative
153 likelihood <code>weight(x)</code>. The probability of each item being selected is
154 therefore <code>weight(x) / s</code>, where <code>s</code> is the sum of all <code>weight(x)</code>.</p>
155 <p>If all of the weights are equal, even if they are all zero, each element has
156 an equal likelihood of being selected.</p>
157 <p>The complexity of this method depends on the feature <code>partition_at_index</code>.
158 If the feature is enabled, then for slices of length <code>n</code>, the complexity
159 is <code>O(n)</code> space and <code>O(n)</code> time. Otherwise, the complexity is <code>O(n)</code> space and
160 <code>O(n * log amount)</code> time.</p>
161 <h5 id="example-3"><a class="doc-anchor" href="#example-3">§</a>Example</h5>
162 <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>rand::prelude::<span class="kw-2">*</span>;
164 <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>)];
165 <span class="kw">let </span><span class="kw-2">mut </span>rng = thread_rng();
166 <span class="comment">// First Draw * Second Draw = total odds
167 // -----------------------
168 // (50% * 50%) + (25% * 67%) = 41.7% chance that the output is `['a', 'b']` in some order.
169 // (50% * 50%) + (25% * 67%) = 41.7% chance that the output is `['a', 'c']` in some order.
170 // (25% * 33%) + (25% * 33%) = 16.6% chance that the output is `['b', 'c']` in some order.
171 </span><span class="macro">println!</span>(<span class="string">"{:?}"</span>, choices.choose_multiple_weighted(<span class="kw-2">&mut </span>rng, <span class="number">2</span>, |item| item.<span class="number">1</span>).unwrap().collect::<Vec<<span class="kw">_</span>>>());</code></pre></div>
172 </div></details><details class="toggle method-toggle" open><summary><section id="tymethod.shuffle" class="method"><a class="src rightside" href="https://rust-random.github.io/rand/src/rand/seq/mod.rs.html#244-245">source</a><h4 class="code-header">fn <a href="#tymethod.shuffle" class="fn">shuffle</a><R>(&mut self, rng: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut R</a>)<div class="where">where
173 R: <a class="trait" href="../trait.Rng.html" title="trait bdk_chain::bitcoin::secp256k1::rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/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>
174 <p>For slices of length <code>n</code>, complexity is <code>O(n)</code>.</p>
175 <h5 id="example-4"><a class="doc-anchor" href="#example-4">§</a>Example</h5>
176 <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>rand::seq::SliceRandom;
177 <span class="kw">use </span>rand::thread_rng;
179 <span class="kw">let </span><span class="kw-2">mut </span>rng = thread_rng();
180 <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>];
181 <span class="macro">println!</span>(<span class="string">"Unshuffled: {:?}"</span>, y);
182 y.shuffle(<span class="kw-2">&mut </span>rng);
183 <span class="macro">println!</span>(<span class="string">"Shuffled: {:?}"</span>, y);</code></pre></div>
184 </div></details><details class="toggle method-toggle" open><summary><section id="tymethod.partial_shuffle" class="method"><a class="src rightside" href="https://rust-random.github.io/rand/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><R>(
186 rng: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut R</a>,
187 amount: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>
188 ) -> (&mut [Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom::Item">Item</a>], &mut [Self::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom::Item">Item</a>])<div class="where">where
189 R: <a class="trait" href="../trait.Rng.html" title="trait bdk_chain::bitcoin::secp256k1::rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/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>
190 <p>Returns two mutable slices from the source slice. The first contains
191 <code>amount</code> elements randomly permuted. The second has the remaining
192 elements that are not fully shuffled.</p>
193 <p>This is an efficient method to select <code>amount</code> elements at random from
194 the slice, provided the slice may be mutated.</p>
195 <p>If you only need to choose elements randomly and <code>amount > self.len()/2</code>
196 then you may improve performance by taking
197 <code>amount = values.len() - amount</code> and using only the second slice.</p>
198 <p>If <code>amount</code> is greater than the number of elements in the slice, this
199 will perform a full shuffle.</p>
200 <p>For slices, complexity is <code>O(m)</code> where <code>m = amount</code>.</p>
201 </div></details></div><h2 id="object-safety" class="section-header">Object Safety<a href="#object-safety" class="anchor">§</a></h2><div class="object-safety-info">This trait is <b>not</b> <a href="https://doc.rust-lang.org/nightly/reference/items/traits.html#object-safety">object safe</a>.</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="https://rust-random.github.io/rand/src/rand/seq/mod.rs.html#492">source</a><a href="#impl-SliceRandom-for-%5BT%5D" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="trait.SliceRandom.html" title="trait bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom">SliceRandom</a> for <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[T]</a></h3></section></summary><div class="impl-items"><section id="associatedtype.Item-1" class="associatedtype trait-impl"><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="https://rust-random.github.io/rand/src/rand/seq/mod.rs.html#495-496">source</a><a href="#method.choose" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.choose" class="fn">choose</a><R>(&self, rng: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut R</a>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><&<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[T]</a> as <a class="trait" href="trait.SliceRandom.html" title="trait bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom">SliceRandom</a>>::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom::Item">Item</a>><div class="where">where
202 R: <a class="trait" href="../trait.Rng.html" title="trait bdk_chain::bitcoin::secp256k1::rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/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="https://rust-random.github.io/rand/src/rand/seq/mod.rs.html#504-505">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><R>(
204 rng: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut R</a>
205 ) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><&mut <<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[T]</a> as <a class="trait" href="trait.SliceRandom.html" title="trait bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom">SliceRandom</a>>::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom::Item">Item</a>><div class="where">where
206 R: <a class="trait" href="../trait.Rng.html" title="trait bdk_chain::bitcoin::secp256k1::rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/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="https://rust-random.github.io/rand/src/rand/seq/mod.rs.html#515-516">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><R>(
208 rng: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut R</a>,
209 amount: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>
210 ) -> <a class="struct" href="struct.SliceChooseIter.html" title="struct bdk_chain::bitcoin::secp256k1::rand::seq::SliceChooseIter">SliceChooseIter</a><'_, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[T]</a>, <<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[T]</a> as <a class="trait" href="trait.SliceRandom.html" title="trait bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom">SliceRandom</a>>::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom::Item">Item</a>> <a href="#" class="tooltip" data-notable-ty="SliceChooseIter<'_, [T], <[T] as SliceRandom>::Item>">ⓘ</a><div class="where">where
211 R: <a class="trait" href="../trait.Rng.html" title="trait bdk_chain::bitcoin::secp256k1::rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/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="https://rust-random.github.io/rand/src/rand/seq/mod.rs.html#526-537">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><R, F, B, X>(
213 rng: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut R</a>,
215 ) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><&<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[T]</a> as <a class="trait" href="trait.SliceRandom.html" title="trait bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom">SliceRandom</a>>::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom::Item">Item</a>, <a class="enum" href="../distributions/enum.WeightedError.html" title="enum bdk_chain::bitcoin::secp256k1::rand::distributions::WeightedError">WeightedError</a>><div class="where">where
216 R: <a class="trait" href="../trait.Rng.html" title="trait bdk_chain::bitcoin::secp256k1::rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
217 F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(&<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[T]</a> as <a class="trait" href="trait.SliceRandom.html" title="trait bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom">SliceRandom</a>>::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom::Item">Item</a>) -> B,
218 B: <a class="trait" href="../distributions/uniform/trait.SampleBorrow.html" title="trait bdk_chain::bitcoin::secp256k1::rand::distributions::uniform::SampleBorrow">SampleBorrow</a><X>,
219 X: <a class="trait" href="../distributions/uniform/trait.SampleUniform.html" title="trait bdk_chain::bitcoin::secp256k1::rand::distributions::uniform::SampleUniform">SampleUniform</a> + for<'a> <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/arith/trait.AddAssign.html" title="trait core::ops::arith::AddAssign">AddAssign</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a X</a>> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/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="https://rust-random.github.io/rand/src/rand/seq/mod.rs.html#545-556">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><R, F, B, X>(
221 rng: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut R</a>,
223 ) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><&mut <<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[T]</a> as <a class="trait" href="trait.SliceRandom.html" title="trait bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom">SliceRandom</a>>::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom::Item">Item</a>, <a class="enum" href="../distributions/enum.WeightedError.html" title="enum bdk_chain::bitcoin::secp256k1::rand::distributions::WeightedError">WeightedError</a>><div class="where">where
224 R: <a class="trait" href="../trait.Rng.html" title="trait bdk_chain::bitcoin::secp256k1::rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
225 F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(&<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[T]</a> as <a class="trait" href="trait.SliceRandom.html" title="trait bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom">SliceRandom</a>>::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom::Item">Item</a>) -> B,
226 B: <a class="trait" href="../distributions/uniform/trait.SampleBorrow.html" title="trait bdk_chain::bitcoin::secp256k1::rand::distributions::uniform::SampleBorrow">SampleBorrow</a><X>,
227 X: <a class="trait" href="../distributions/uniform/trait.SampleUniform.html" title="trait bdk_chain::bitcoin::secp256k1::rand::distributions::uniform::SampleUniform">SampleUniform</a> + for<'a> <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/arith/trait.AddAssign.html" title="trait core::ops::arith::AddAssign">AddAssign</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a X</a>> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/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="https://rust-random.github.io/rand/src/rand/seq/mod.rs.html#564-570">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><R, F, X>(
229 rng: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut R</a>,
230 amount: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>,
232 ) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="struct.SliceChooseIter.html" title="struct bdk_chain::bitcoin::secp256k1::rand::seq::SliceChooseIter">SliceChooseIter</a><'_, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[T]</a>, <<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[T]</a> as <a class="trait" href="trait.SliceRandom.html" title="trait bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom">SliceRandom</a>>::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom::Item">Item</a>>, <a class="enum" href="../distributions/enum.WeightedError.html" title="enum bdk_chain::bitcoin::secp256k1::rand::distributions::WeightedError">WeightedError</a>><div class="where">where
233 R: <a class="trait" href="../trait.Rng.html" title="trait bdk_chain::bitcoin::secp256k1::rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
234 F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(&<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[T]</a> as <a class="trait" href="trait.SliceRandom.html" title="trait bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom">SliceRandom</a>>::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom::Item">Item</a>) -> X,
235 X: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.f64.html">f64</a>>,</div></h4></section><section id="method.shuffle" class="method trait-impl"><a class="src rightside" href="https://rust-random.github.io/rand/src/rand/seq/mod.rs.html#586-587">source</a><a href="#method.shuffle" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.shuffle" class="fn">shuffle</a><R>(&mut self, rng: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut R</a>)<div class="where">where
236 R: <a class="trait" href="../trait.Rng.html" title="trait bdk_chain::bitcoin::secp256k1::rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/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="https://rust-random.github.io/rand/src/rand/seq/mod.rs.html#594-597">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><R>(
238 rng: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut R</a>,
239 amount: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>
240 ) -> (&mut [<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[T]</a> as <a class="trait" href="trait.SliceRandom.html" title="trait bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom">SliceRandom</a>>::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom::Item">Item</a>], &mut [<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[T]</a> as <a class="trait" href="trait.SliceRandom.html" title="trait bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom">SliceRandom</a>>::<a class="associatedtype" href="trait.SliceRandom.html#associatedtype.Item" title="type bdk_chain::bitcoin::secp256k1::rand::seq::SliceRandom::Item">Item</a>])<div class="where">where
241 R: <a class="trait" href="../trait.Rng.html" title="trait bdk_chain::bitcoin::secp256k1::rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/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 bdk_chain::bitcoin::secp256k1::rand::seq::SliceChooseIter\">SliceChooseIter</a><'a, S, T></code></h3><pre><code><div class=\"where\">impl<'a, S, T> <a class=\"trait\" href=\"https://doc.rust-lang.org/nightly/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 bdk_chain::bitcoin::secp256k1::rand::seq::SliceChooseIter\">SliceChooseIter</a><'a, S, T><div class=\"where\">where\n S: <a class=\"trait\" href=\"https://doc.rust-lang.org/nightly/core/ops/index/trait.Index.html\" title=\"trait core::ops::index::Index\">Index</a><<a class=\"primitive\" href=\"https://doc.rust-lang.org/nightly/std/primitive.usize.html\">usize</a>, Output = T> + 'a + ?<a class=\"trait\" href=\"https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html\" title=\"trait core::marker::Sized\">Sized</a>,\n T: 'a,</div></div><div class=\"where\"> type <a href=\"https://doc.rust-lang.org/nightly/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item\" class=\"associatedtype\">Item</a> = <a class=\"primitive\" href=\"https://doc.rust-lang.org/nightly/std/primitive.reference.html\">&'a T</a>;</div>","SliceChooseIter<'_, [T], <[T] as SliceRandom>::Item>":"<h3>Notable traits for <code><a class=\"struct\" href=\"struct.SliceChooseIter.html\" title=\"struct bdk_chain::bitcoin::secp256k1::rand::seq::SliceChooseIter\">SliceChooseIter</a><'a, S, T></code></h3><pre><code><div class=\"where\">impl<'a, S, T> <a class=\"trait\" href=\"https://doc.rust-lang.org/nightly/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 bdk_chain::bitcoin::secp256k1::rand::seq::SliceChooseIter\">SliceChooseIter</a><'a, S, T><div class=\"where\">where\n S: <a class=\"trait\" href=\"https://doc.rust-lang.org/nightly/core/ops/index/trait.Index.html\" title=\"trait core::ops::index::Index\">Index</a><<a class=\"primitive\" href=\"https://doc.rust-lang.org/nightly/std/primitive.usize.html\">usize</a>, Output = T> + 'a + ?<a class=\"trait\" href=\"https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html\" title=\"trait core::marker::Sized\">Sized</a>,\n T: 'a,</div></div><div class=\"where\"> type <a href=\"https://doc.rust-lang.org/nightly/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item\" class=\"associatedtype\">Item</a> = <a class=\"primitive\" href=\"https://doc.rust-lang.org/nightly/std/primitive.reference.html\">&'a T</a>;</div>"}</script></section></div></main></body></html>