deploy: de38ae62916547ad097c066f94a32e9ba7790eeb

This commit is contained in:
NotAShelf 2025-02-05 00:10:33 +00:00
commit 9a86359447
28502 changed files with 1261284 additions and 0 deletions

1
rand/all.html Normal file

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../../rand/distributions/enum.BernoulliError.html">
<title>Redirection</title>
</head>
<body>
<p>Redirecting to <a href="../../../rand/distributions/enum.BernoulliError.html">../../../rand/distributions/enum.BernoulliError.html</a>...</p>
<script>location.replace("../../../rand/distributions/enum.BernoulliError.html" + location.search + location.hash);</script>
</body>
</html>

View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../../rand/distributions/struct.Bernoulli.html">
<title>Redirection</title>
</head>
<body>
<p>Redirecting to <a href="../../../rand/distributions/struct.Bernoulli.html">../../../rand/distributions/struct.Bernoulli.html</a>...</p>
<script>location.replace("../../../rand/distributions/struct.Bernoulli.html" + location.search + location.hash);</script>
</body>
</html>

View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../../rand/distributions/struct.DistIter.html">
<title>Redirection</title>
</head>
<body>
<p>Redirecting to <a href="../../../rand/distributions/struct.DistIter.html">../../../rand/distributions/struct.DistIter.html</a>...</p>
<script>location.replace("../../../rand/distributions/struct.DistIter.html" + location.search + location.hash);</script>
</body>
</html>

View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../../rand/distributions/struct.DistMap.html">
<title>Redirection</title>
</head>
<body>
<p>Redirecting to <a href="../../../rand/distributions/struct.DistMap.html">../../../rand/distributions/struct.DistMap.html</a>...</p>
<script>location.replace("../../../rand/distributions/struct.DistMap.html" + location.search + location.hash);</script>
</body>
</html>

View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../../rand/distributions/trait.DistString.html">
<title>Redirection</title>
</head>
<body>
<p>Redirecting to <a href="../../../rand/distributions/trait.DistString.html">../../../rand/distributions/trait.DistString.html</a>...</p>
<script>location.replace("../../../rand/distributions/trait.DistString.html" + location.search + location.hash);</script>
</body>
</html>

View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../../rand/distributions/trait.Distribution.html">
<title>Redirection</title>
</head>
<body>
<p>Redirecting to <a href="../../../rand/distributions/trait.Distribution.html">../../../rand/distributions/trait.Distribution.html</a>...</p>
<script>location.replace("../../../rand/distributions/trait.Distribution.html" + location.search + location.hash);</script>
</body>
</html>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../../rand/distributions/struct.Open01.html">
<title>Redirection</title>
</head>
<body>
<p>Redirecting to <a href="../../../rand/distributions/struct.Open01.html">../../../rand/distributions/struct.Open01.html</a>...</p>
<script>location.replace("../../../rand/distributions/struct.Open01.html" + location.search + location.hash);</script>
</body>
</html>

View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../../rand/distributions/struct.OpenClosed01.html">
<title>Redirection</title>
</head>
<body>
<p>Redirecting to <a href="../../../rand/distributions/struct.OpenClosed01.html">../../../rand/distributions/struct.OpenClosed01.html</a>...</p>
<script>location.replace("../../../rand/distributions/struct.OpenClosed01.html" + location.search + location.hash);</script>
</body>
</html>

View file

@ -0,0 +1,63 @@
<!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="Generating random samples from probability distributions"><title>rand::distributions - 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 mod"><!--[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="#">Module distributions</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#the-standard-distribution" title="The `Standard` distribution">The <code>Standard</code> distribution</a><ul><li><a href="#random-characters" title="Random characters">Random characters</a></li></ul></li><li><a href="#uniform-numeric-ranges" title="Uniform numeric ranges">Uniform numeric ranges</a><ul><li><a href="#open-and-half-open-ranges" title="Open and half-open ranges">Open and half-open ranges</a></li></ul></li><li><a href="#non-uniform-sampling" title="Non-uniform sampling">Non-uniform sampling</a></li></ul><h3><a href="#modules">Module Items</a></h3><ul class="block"><li><a href="#modules" title="Modules">Modules</a></li><li><a href="#structs" title="Structs">Structs</a></li><li><a href="#enums" title="Enums">Enums</a></li><li><a href="#traits" title="Traits">Traits</a></li></ul></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="../index.html">In crate rand</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></span><h1>Module <span>distributions</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/distributions/mod.rs.html#10-218">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Generating random samples from probability distributions</p>
<p>This module is the home of the <a href="trait.Distribution.html" title="trait rand::distributions::Distribution"><code>Distribution</code></a> trait and several of its
implementations. It is the workhorse behind some of the convenient
functionality of the <a href="../trait.Rng.html" title="trait rand::Rng"><code>Rng</code></a> trait, e.g. <a href="../trait.Rng.html#method.gen" title="method rand::Rng::gen"><code>Rng::gen</code></a> and of course
<a href="../trait.Rng.html#method.sample" title="method rand::Rng::sample"><code>Rng::sample</code></a>.</p>
<p>Abstractly, a <a href="https://en.wikipedia.org/wiki/Probability_distribution">probability distribution</a> describes the probability of
occurrence of each value in its sample space.</p>
<p>More concretely, an implementation of <code>Distribution&lt;T&gt;</code> for type <code>X</code> is an
algorithm for choosing values from the sample space (a subset of <code>T</code>)
according to the distribution <code>X</code> represents, using an external source of
randomness (an RNG supplied to the <code>sample</code> function).</p>
<p>A type <code>X</code> may implement <code>Distribution&lt;T&gt;</code> for multiple types <code>T</code>.
Any type implementing <a href="trait.Distribution.html" title="trait rand::distributions::Distribution"><code>Distribution</code></a> is stateless (i.e. immutable),
but it may have internal parameters set at construction time (for example,
<a href="struct.Uniform.html" title="struct rand::distributions::Uniform"><code>Uniform</code></a> allows specification of its sample space as a range within <code>T</code>).</p>
<h2 id="the-standard-distribution"><a class="doc-anchor" href="#the-standard-distribution">§</a>The <code>Standard</code> distribution</h2>
<p>The <a href="struct.Standard.html" title="struct rand::distributions::Standard"><code>Standard</code></a> distribution is important to mention. This is the
distribution used by <a href="../trait.Rng.html#method.gen" title="method rand::Rng::gen"><code>Rng::gen</code></a> and represents the “default” way to
produce a random value for many different types, including most primitive
types, tuples, arrays, and a few derived types. See the documentation of
<a href="struct.Standard.html" title="struct rand::distributions::Standard"><code>Standard</code></a> for more details.</p>
<p>Implementing <code>Distribution&lt;T&gt;</code> for <a href="struct.Standard.html" title="struct rand::distributions::Standard"><code>Standard</code></a> for user types <code>T</code> makes it
possible to generate type <code>T</code> with <a href="../trait.Rng.html#method.gen" title="method rand::Rng::gen"><code>Rng::gen</code></a>, and by extension also
with the <a href="../fn.random.html" title="fn rand::random"><code>random</code></a> function.</p>
<h3 id="random-characters"><a class="doc-anchor" href="#random-characters">§</a>Random characters</h3>
<p><a href="struct.Alphanumeric.html" title="struct rand::distributions::Alphanumeric"><code>Alphanumeric</code></a> is a simple distribution to sample random letters and
numbers of the <code>char</code> type; in contrast <a href="struct.Standard.html" title="struct rand::distributions::Standard"><code>Standard</code></a> may sample any valid
<code>char</code>.</p>
<h2 id="uniform-numeric-ranges"><a class="doc-anchor" href="#uniform-numeric-ranges">§</a>Uniform numeric ranges</h2>
<p>The <a href="struct.Uniform.html" title="struct rand::distributions::Uniform"><code>Uniform</code></a> distribution is more flexible than <a href="struct.Standard.html" title="struct rand::distributions::Standard"><code>Standard</code></a>, but also
more specialised: it supports fewer target types, but allows the sample
space to be specified as an arbitrary range within its target type <code>T</code>.
Both <a href="struct.Standard.html" title="struct rand::distributions::Standard"><code>Standard</code></a> and <a href="struct.Uniform.html" title="struct rand::distributions::Uniform"><code>Uniform</code></a> are in some sense uniform distributions.</p>
<p>Values may be sampled from this distribution using [<code>Rng::sample(Range)</code>] or
by creating a distribution object with <a href="struct.Uniform.html#method.new" title="associated function rand::distributions::Uniform::new"><code>Uniform::new</code></a>,
<a href="struct.Uniform.html#method.new_inclusive" title="associated function rand::distributions::Uniform::new_inclusive"><code>Uniform::new_inclusive</code></a> or <code>From&lt;Range&gt;</code>. When the range limits are not
known at compile time it is typically faster to reuse an existing
<code>Uniform</code> object than to call [<code>Rng::sample(Range)</code>].</p>
<p>User types <code>T</code> may also implement <code>Distribution&lt;T&gt;</code> for <a href="struct.Uniform.html" title="struct rand::distributions::Uniform"><code>Uniform</code></a>,
although this is less straightforward than for <a href="struct.Standard.html" title="struct rand::distributions::Standard"><code>Standard</code></a> (see the
documentation in the <a href="uniform/index.html" title="mod rand::distributions::uniform"><code>uniform</code></a> module). Doing so enables generation of
values of type <code>T</code> with [<code>Rng::sample(Range)</code>].</p>
<h3 id="open-and-half-open-ranges"><a class="doc-anchor" href="#open-and-half-open-ranges">§</a>Open and half-open ranges</h3>
<p>There are surprisingly many ways to uniformly generate random floats. A
range between 0 and 1 is standard, but the exact bounds (open vs closed)
and accuracy differ. In addition to the <a href="struct.Standard.html" title="struct rand::distributions::Standard"><code>Standard</code></a> distribution Rand offers
<a href="struct.Open01.html" title="struct rand::distributions::Open01"><code>Open01</code></a> and <a href="struct.OpenClosed01.html" title="struct rand::distributions::OpenClosed01"><code>OpenClosed01</code></a>. See “Floating point implementation” section of
<a href="struct.Standard.html" title="struct rand::distributions::Standard"><code>Standard</code></a> documentation for more details.</p>
<h2 id="non-uniform-sampling"><a class="doc-anchor" href="#non-uniform-sampling">§</a>Non-uniform sampling</h2>
<p>Sampling a simple true/false outcome with a given probability has a name:
the <a href="struct.Bernoulli.html" title="struct rand::distributions::Bernoulli"><code>Bernoulli</code></a> distribution (this is used by <a href="../trait.Rng.html#method.gen_bool" title="method rand::Rng::gen_bool"><code>Rng::gen_bool</code></a>).</p>
<p>For weighted sampling from a sequence of discrete values, use the
<a href="struct.WeightedIndex.html" title="struct rand::distributions::WeightedIndex"><code>WeightedIndex</code></a> distribution.</p>
<p>This crate no longer includes other non-uniform distributions; instead
it is recommended that you use either <a href="https://crates.io/crates/rand_distr"><code>rand_distr</code></a> or <a href="https://crates.io/crates/statrs"><code>statrs</code></a>.</p>
</div></details><h2 id="modules" class="section-header">Modules<a href="#modules" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="mod" href="uniform/index.html" title="mod rand::distributions::uniform">uniform</a></div><div class="desc docblock-short">A distribution uniformly sampling numbers within a given range.</div></li><li><div class="item-name"><a class="mod" href="weighted/index.html" title="mod rand::distributions::weighted">weighted</a><wbr><span class="stab deprecated" title="">Deprecated</span></div><div class="desc docblock-short">Weighted index sampling</div></li></ul><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="struct" href="struct.Alphanumeric.html" title="struct rand::distributions::Alphanumeric">Alphanumeric</a></div><div class="desc docblock-short">Sample a <code>u8</code>, uniformly distributed over ASCII letters and numbers:
a-z, A-Z and 0-9.</div></li><li><div class="item-name"><a class="struct" href="struct.Bernoulli.html" title="struct rand::distributions::Bernoulli">Bernoulli</a></div><div class="desc docblock-short">The Bernoulli distribution.</div></li><li><div class="item-name"><a class="struct" href="struct.DistIter.html" title="struct rand::distributions::DistIter">Dist<wbr>Iter</a></div><div class="desc docblock-short">An iterator that generates random values of <code>T</code> with distribution <code>D</code>,
using <code>R</code> as the source of randomness.</div></li><li><div class="item-name"><a class="struct" href="struct.DistMap.html" title="struct rand::distributions::DistMap">DistMap</a></div><div class="desc docblock-short">A distribution of values of type <code>S</code> derived from the distribution <code>D</code>
by mapping its output of type <code>T</code> through the closure <code>F</code>.</div></li><li><div class="item-name"><a class="struct" href="struct.Open01.html" title="struct rand::distributions::Open01">Open01</a></div><div class="desc docblock-short">A distribution to sample floating point numbers uniformly in the open
interval <code>(0, 1)</code>, i.e. not including either endpoint.</div></li><li><div class="item-name"><a class="struct" href="struct.OpenClosed01.html" title="struct rand::distributions::OpenClosed01">Open<wbr>Closed01</a></div><div class="desc docblock-short">A distribution to sample floating point numbers uniformly in the half-open
interval <code>(0, 1]</code>, i.e. including 1 but not 0.</div></li><li><div class="item-name"><a class="struct" href="struct.Slice.html" title="struct rand::distributions::Slice">Slice</a></div><div class="desc docblock-short">A distribution to sample items uniformly from a slice.</div></li><li><div class="item-name"><a class="struct" href="struct.Standard.html" title="struct rand::distributions::Standard">Standard</a></div><div class="desc docblock-short">A generic random value distribution, implemented for many primitive types.
Usually generates values with a numerically uniform distribution, and with a
range appropriate to the type.</div></li><li><div class="item-name"><a class="struct" href="struct.Uniform.html" title="struct rand::distributions::Uniform">Uniform</a></div><div class="desc docblock-short">Sample values uniformly between two bounds.</div></li><li><div class="item-name"><a class="struct" href="struct.WeightedIndex.html" title="struct rand::distributions::WeightedIndex">Weighted<wbr>Index</a></div><div class="desc docblock-short">A distribution using weighted sampling of discrete items</div></li></ul><h2 id="enums" class="section-header">Enums<a href="#enums" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="enum" href="enum.BernoulliError.html" title="enum rand::distributions::BernoulliError">Bernoulli<wbr>Error</a></div><div class="desc docblock-short">Error type returned from <code>Bernoulli::new</code>.</div></li><li><div class="item-name"><a class="enum" href="enum.WeightedError.html" title="enum rand::distributions::WeightedError">Weighted<wbr>Error</a></div><div class="desc docblock-short">Error type returned from <code>WeightedIndex::new</code>.</div></li></ul><h2 id="traits" class="section-header">Traits<a href="#traits" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="trait" href="trait.DistString.html" title="trait rand::distributions::DistString">Dist<wbr>String</a></div><div class="desc docblock-short"><code>String</code> sampler</div></li><li><div class="item-name"><a class="trait" href="trait.Distribution.html" title="trait rand::distributions::Distribution">Distribution</a></div><div class="desc docblock-short">Types (distributions) that can be used to create a random instance of <code>T</code>.</div></li></ul></section></div></main></body></html>

View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../../rand/distributions/struct.Alphanumeric.html">
<title>Redirection</title>
</head>
<body>
<p>Redirecting to <a href="../../../rand/distributions/struct.Alphanumeric.html">../../../rand/distributions/struct.Alphanumeric.html</a>...</p>
<script>location.replace("../../../rand/distributions/struct.Alphanumeric.html" + location.search + location.hash);</script>
</body>
</html>

View file

@ -0,0 +1 @@
window.SIDEBAR_ITEMS = {"enum":["BernoulliError","WeightedError"],"mod":["uniform","weighted"],"struct":["Alphanumeric","Bernoulli","DistIter","DistMap","Open01","OpenClosed01","Slice","Standard","Uniform","WeightedIndex"],"trait":["DistString","Distribution"]};

View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../../rand/distributions/struct.Slice.html">
<title>Redirection</title>
</head>
<body>
<p>Redirecting to <a href="../../../rand/distributions/struct.Slice.html">../../../rand/distributions/struct.Slice.html</a>...</p>
<script>location.replace("../../../rand/distributions/struct.Slice.html" + location.search + location.hash);</script>
</body>
</html>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,24 @@
<!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="`String` sampler"><title>DistString in rand::distributions - 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="#">Dist<wbr>String</a></h2><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.append_string" title="append_string">append_string</a></li></ul><h3><a href="#provided-methods">Provided Methods</a></h3><ul class="block"><li><a href="#method.sample_string" title="sample_string">sample_string</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>distributions</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">distributions</a></span><h1>Trait <span class="trait">DistString</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/distributions/distribution.rs.html#197-208">Source</a> </span></div><pre class="rust item-decl"><code>pub trait DistString {
// Required method
fn <a href="#tymethod.append_string" class="fn">append_string</a>&lt;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>&gt;(
&amp;self,
rng: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;mut R</a>,
string: &amp;mut <a class="struct" href="https://doc.rust-lang.org/1.84.1/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>,
len: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.usize.html">usize</a>,
);
// Provided method
fn <a href="#method.sample_string" class="fn">sample_string</a>&lt;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>&gt;(&amp;self, rng: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;mut R</a>, len: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.usize.html">usize</a>) -&gt; <a class="struct" href="https://doc.rust-lang.org/1.84.1/alloc/string/struct.String.html" title="struct alloc::string::String">String</a> { ... }
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p><code>String</code> sampler</p>
<p>Sampling a <code>String</code> of random characters is not quite the same as collecting
a sequence of chars. This trait contains some helpers.</p>
</div></details><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.append_string" class="method"><a class="src rightside" href="../../src/rand/distributions/distribution.rs.html#199">Source</a><h4 class="code-header">fn <a href="#tymethod.append_string" class="fn">append_string</a>&lt;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>&gt;(
&amp;self,
rng: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;mut R</a>,
string: &amp;mut <a class="struct" href="https://doc.rust-lang.org/1.84.1/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>,
len: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.usize.html">usize</a>,
)</h4></section></summary><div class="docblock"><p>Append <code>len</code> random chars to <code>string</code></p>
</div></details></div><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.sample_string" class="method"><a class="src rightside" href="../../src/rand/distributions/distribution.rs.html#203-207">Source</a><h4 class="code-header">fn <a href="#method.sample_string" class="fn">sample_string</a>&lt;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>&gt;(&amp;self, rng: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;mut R</a>, len: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.usize.html">usize</a>) -&gt; <a class="struct" href="https://doc.rust-lang.org/1.84.1/alloc/string/struct.String.html" title="struct alloc::string::String">String</a></h4></section></summary><div class="docblock"><p>Generate a <code>String</code> of <code>len</code> random chars</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="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"><section id="impl-DistString-for-Alphanumeric" class="impl"><a class="src rightside" href="../../src/rand/distributions/other.rs.html#128-135">Source</a><a href="#impl-DistString-for-Alphanumeric" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.DistString.html" title="trait rand::distributions::DistString">DistString</a> for <a class="struct" href="struct.Alphanumeric.html" title="struct rand::distributions::Alphanumeric">Alphanumeric</a></h3></section><section id="impl-DistString-for-Standard" class="impl"><a class="src rightside" href="../../src/rand/distributions/other.rs.html#98-106">Source</a><a href="#impl-DistString-for-Standard" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.DistString.html" title="trait rand::distributions::DistString">DistString</a> for <a class="struct" href="struct.Standard.html" title="struct rand::distributions::Standard">Standard</a></h3></section><div class="docblock"><p>Note: the <code>String</code> is potentially left with excess capacity; optionally the
user may call <code>string.shrink_to_fit()</code> afterwards.</p>
</div></div><script src="../../trait.impl/rand/distributions/distribution/trait.DistString.js" async></script></section></div></main></body></html>

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,82 @@
<!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="A distribution uniformly sampling numbers within a given range."><title>rand::distributions::uniform - 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 mod"><!--[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="#">Module uniform</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#example-usage" title="Example usage">Example usage</a></li><li><a href="#extending-uniform-to-support-a-custom-type" title="Extending `Uniform` to support a custom type">Extending <code>Uniform</code> to support a custom type</a></li></ul><h3><a href="#structs">Module Items</a></h3><ul class="block"><li><a href="#structs" title="Structs">Structs</a></li><li><a href="#traits" title="Traits">Traits</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="../index.html">In rand::<wbr>distributions</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">distributions</a></span><h1>Module <span>uniform</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/distributions/uniform.rs.html#10-1658">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>A distribution uniformly sampling numbers within a given range.</p>
<p><a href="../struct.Uniform.html" title="struct rand::distributions::Uniform"><code>Uniform</code></a> is the standard distribution to sample uniformly from a range;
e.g. <code>Uniform::new_inclusive(1, 6)</code> can sample integers from 1 to 6, like a
standard die. <a href="../../trait.Rng.html#method.gen_range" title="method rand::Rng::gen_range"><code>Rng::gen_range</code></a> supports any type supported by
<a href="../struct.Uniform.html" title="struct rand::distributions::Uniform"><code>Uniform</code></a>.</p>
<p>This distribution is provided with support for several primitive types
(all integer and floating-point types) as well as <a href="https://doc.rust-lang.org/1.84.1/core/time/struct.Duration.html" title="struct core::time::Duration"><code>std::time::Duration</code></a>,
and supports extension to user-defined types via a type-specific <em>back-end</em>
implementation.</p>
<p>The types <a href="struct.UniformInt.html" title="struct rand::distributions::uniform::UniformInt"><code>UniformInt</code></a>, <a href="struct.UniformFloat.html" title="struct rand::distributions::uniform::UniformFloat"><code>UniformFloat</code></a> and <a href="struct.UniformDuration.html" title="struct rand::distributions::uniform::UniformDuration"><code>UniformDuration</code></a> are the
back-ends supporting sampling from primitive integer and floating-point
ranges as well as from <a href="https://doc.rust-lang.org/1.84.1/core/time/struct.Duration.html" title="struct core::time::Duration"><code>std::time::Duration</code></a>; these types do not normally
need to be used directly (unless implementing a derived back-end).</p>
<h2 id="example-usage"><a class="doc-anchor" href="#example-usage">§</a>Example usage</h2>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>rand::{Rng, thread_rng};
<span class="kw">use </span>rand::distributions::Uniform;
<span class="kw">let </span><span class="kw-2">mut </span>rng = thread_rng();
<span class="kw">let </span>side = Uniform::new(-<span class="number">10.0</span>, <span class="number">10.0</span>);
<span class="comment">// sample between 1 and 10 points
</span><span class="kw">for _ in </span><span class="number">0</span>..rng.gen_range(<span class="number">1</span>..=<span class="number">10</span>) {
<span class="comment">// sample a point from the square with sides -10 - 10 in two dimensions
</span><span class="kw">let </span>(x, y) = (rng.sample(side), rng.sample(side));
<span class="macro">println!</span>(<span class="string">"Point: {}, {}"</span>, x, y);
}</code></pre></div>
<h2 id="extending-uniform-to-support-a-custom-type"><a class="doc-anchor" href="#extending-uniform-to-support-a-custom-type">§</a>Extending <code>Uniform</code> to support a custom type</h2>
<p>To extend <a href="../struct.Uniform.html" title="struct rand::distributions::Uniform"><code>Uniform</code></a> to support your own types, write a back-end which
implements the <a href="trait.UniformSampler.html" title="trait rand::distributions::uniform::UniformSampler"><code>UniformSampler</code></a> trait, then implement the <a href="trait.SampleUniform.html" title="trait rand::distributions::uniform::SampleUniform"><code>SampleUniform</code></a>
helper trait to “register” your back-end. See the <code>MyF32</code> example below.</p>
<p>At a minimum, the back-end needs to store any parameters needed for sampling
(e.g. the target range) and implement <code>new</code>, <code>new_inclusive</code> and <code>sample</code>.
Those methods should include an assert to check the range is valid (i.e.
<code>low &lt; high</code>). The example below merely wraps another back-end.</p>
<p>The <code>new</code>, <code>new_inclusive</code> and <code>sample_single</code> functions use arguments of
type SampleBorrow<X> in order to support passing in values by reference or
by value. In the implementation of these functions, you can choose to
simply use the reference returned by <a href="trait.SampleBorrow.html#tymethod.borrow" title="method rand::distributions::uniform::SampleBorrow::borrow"><code>SampleBorrow::borrow</code></a>, or you can choose
to copy or clone the value, whatever is appropriate for your type.</p>
<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">use </span>rand::distributions::uniform::{Uniform, SampleUniform,
UniformSampler, UniformFloat, SampleBorrow};
<span class="kw">struct </span>MyF32(f32);
<span class="attr">#[derive(Clone, Copy, Debug)]
</span><span class="kw">struct </span>UniformMyF32(UniformFloat&lt;f32&gt;);
<span class="kw">impl </span>UniformSampler <span class="kw">for </span>UniformMyF32 {
<span class="kw">type </span>X = MyF32;
<span class="kw">fn </span>new&lt;B1, B2&gt;(low: B1, high: B2) -&gt; <span class="self">Self
</span><span class="kw">where </span>B1: SampleBorrow&lt;<span class="self">Self</span>::X&gt; + Sized,
B2: SampleBorrow&lt;<span class="self">Self</span>::X&gt; + Sized
{
UniformMyF32(UniformFloat::&lt;f32&gt;::new(low.borrow().<span class="number">0</span>, high.borrow().<span class="number">0</span>))
}
<span class="kw">fn </span>new_inclusive&lt;B1, B2&gt;(low: B1, high: B2) -&gt; <span class="self">Self
</span><span class="kw">where </span>B1: SampleBorrow&lt;<span class="self">Self</span>::X&gt; + Sized,
B2: SampleBorrow&lt;<span class="self">Self</span>::X&gt; + Sized
{
UniformMyF32(UniformFloat::&lt;f32&gt;::new_inclusive(
low.borrow().<span class="number">0</span>,
high.borrow().<span class="number">0</span>,
))
}
<span class="kw">fn </span>sample&lt;R: Rng + <span class="question-mark">?</span>Sized&gt;(<span class="kw-2">&amp;</span><span class="self">self</span>, rng: <span class="kw-2">&amp;mut </span>R) -&gt; <span class="self">Self</span>::X {
MyF32(<span class="self">self</span>.<span class="number">0</span>.sample(rng))
}
}
<span class="kw">impl </span>SampleUniform <span class="kw">for </span>MyF32 {
<span class="kw">type </span>Sampler = UniformMyF32;
}
<span class="kw">let </span>(low, high) = (MyF32(<span class="number">17.0f32</span>), MyF32(<span class="number">22.0f32</span>));
<span class="kw">let </span>uniform = Uniform::new(low, high);
<span class="kw">let </span>x = uniform.sample(<span class="kw-2">&amp;mut </span>thread_rng());</code></pre></div>
</div></details><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="struct" href="struct.Uniform.html" title="struct rand::distributions::uniform::Uniform">Uniform</a></div><div class="desc docblock-short">Sample values uniformly between two bounds.</div></li><li><div class="item-name"><a class="struct" href="struct.UniformChar.html" title="struct rand::distributions::uniform::UniformChar">Uniform<wbr>Char</a></div><div class="desc docblock-short">The back-end implementing <a href="trait.UniformSampler.html" title="trait rand::distributions::uniform::UniformSampler"><code>UniformSampler</code></a> for <code>char</code>.</div></li><li><div class="item-name"><a class="struct" href="struct.UniformDuration.html" title="struct rand::distributions::uniform::UniformDuration">Uniform<wbr>Duration</a></div><div class="desc docblock-short">The back-end implementing <a href="trait.UniformSampler.html" title="trait rand::distributions::uniform::UniformSampler"><code>UniformSampler</code></a> for <code>Duration</code>.</div></li><li><div class="item-name"><a class="struct" href="struct.UniformFloat.html" title="struct rand::distributions::uniform::UniformFloat">Uniform<wbr>Float</a></div><div class="desc docblock-short">The back-end implementing <a href="trait.UniformSampler.html" title="trait rand::distributions::uniform::UniformSampler"><code>UniformSampler</code></a> for floating-point types.</div></li><li><div class="item-name"><a class="struct" href="struct.UniformInt.html" title="struct rand::distributions::uniform::UniformInt">Uniform<wbr>Int</a></div><div class="desc docblock-short">The back-end implementing <a href="trait.UniformSampler.html" title="trait rand::distributions::uniform::UniformSampler"><code>UniformSampler</code></a> for integer types.</div></li></ul><h2 id="traits" class="section-header">Traits<a href="#traits" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="trait" href="trait.SampleBorrow.html" title="trait rand::distributions::uniform::SampleBorrow">Sample<wbr>Borrow</a></div><div class="desc docblock-short">Helper trait similar to <a href="https://doc.rust-lang.org/1.84.1/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow"><code>Borrow</code></a> but implemented
only for SampleUniform and references to SampleUniform in
order to resolve ambiguity issues.</div></li><li><div class="item-name"><a class="trait" href="trait.SampleRange.html" title="trait rand::distributions::uniform::SampleRange">Sample<wbr>Range</a></div><div class="desc docblock-short">Range that supports generating a single sample efficiently.</div></li><li><div class="item-name"><a class="trait" href="trait.SampleUniform.html" title="trait rand::distributions::uniform::SampleUniform">Sample<wbr>Uniform</a></div><div class="desc docblock-short">Helper trait for creating objects using the correct implementation of
<a href="trait.UniformSampler.html" title="trait rand::distributions::uniform::UniformSampler"><code>UniformSampler</code></a> for the sampling type.</div></li><li><div class="item-name"><a class="trait" href="trait.UniformSampler.html" title="trait rand::distributions::uniform::UniformSampler">Uniform<wbr>Sampler</a></div><div class="desc docblock-short">Helper trait handling actual uniform sampling.</div></li></ul></section></div></main></body></html>

View file

@ -0,0 +1 @@
window.SIDEBAR_ITEMS = {"struct":["Uniform","UniformChar","UniformDuration","UniformFloat","UniformInt"],"trait":["SampleBorrow","SampleRange","SampleUniform","UniformSampler"]};

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,10 @@
<!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="Helper trait similar to `Borrow` but implemented only for SampleUniform and references to SampleUniform in order to resolve ambiguity issues."><title>SampleBorrow in rand::distributions::uniform - 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="#">Sample<wbr>Borrow</a></h2><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.borrow" title="borrow">borrow</a></li></ul><h3><a href="#foreign-impls">Implementations on Foreign Types</a></h3><ul class="block"><li><a href="#impl-SampleBorrow%3CBorrowed%3E-for-%26Borrowed" title="&#38;&#39;a Borrowed">&#38;&#39;a Borrowed</a></li></ul><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2><a href="index.html">In rand::<wbr>distributions::<wbr>uniform</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">distributions</a>::<wbr><a href="index.html">uniform</a></span><h1>Trait <span class="trait">SampleBorrow</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/distributions/uniform.rs.html#322-327">Source</a> </span></div><pre class="rust item-decl"><code>pub trait SampleBorrow&lt;Borrowed&gt; {
// Required method
fn <a href="#tymethod.borrow" class="fn">borrow</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;Borrowed</a>;
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Helper trait similar to <a href="https://doc.rust-lang.org/1.84.1/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow"><code>Borrow</code></a> but implemented
only for SampleUniform and references to SampleUniform in
order to resolve ambiguity issues.</p>
</div></details><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.borrow" class="method"><a class="src rightside" href="../../../src/rand/distributions/uniform.rs.html#326">Source</a><h4 class="code-header">fn <a href="#tymethod.borrow" class="fn">borrow</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;Borrowed</a></h4></section></summary><div class="docblock"><p>Immutably borrows from an owned value. See <a href="https://doc.rust-lang.org/1.84.1/core/borrow/trait.Borrow.html#tymethod.borrow" title="method core::borrow::Borrow::borrow"><code>Borrow::borrow</code></a></p>
</div></details></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-SampleBorrow%3CBorrowed%3E-for-%26Borrowed" class="impl"><a class="src rightside" href="../../../src/rand/distributions/uniform.rs.html#336-343">Source</a><a href="#impl-SampleBorrow%3CBorrowed%3E-for-%26Borrowed" class="anchor">§</a><h3 class="code-header">impl&lt;'a, Borrowed&gt; <a class="trait" href="trait.SampleBorrow.html" title="trait rand::distributions::uniform::SampleBorrow">SampleBorrow</a>&lt;Borrowed&gt; for <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;'a Borrowed</a><div class="where">where
Borrowed: <a class="trait" href="trait.SampleUniform.html" title="trait rand::distributions::uniform::SampleUniform">SampleUniform</a>,</div></h3></section></summary><div class="impl-items"><section id="method.borrow" class="method trait-impl"><a class="src rightside" href="../../../src/rand/distributions/uniform.rs.html#340-342">Source</a><a href="#method.borrow" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.borrow" class="fn">borrow</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;Borrowed</a></h4></section></div></details><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"><section id="impl-SampleBorrow%3CBorrowed%3E-for-Borrowed" class="impl"><a class="src rightside" href="../../../src/rand/distributions/uniform.rs.html#328-335">Source</a><a href="#impl-SampleBorrow%3CBorrowed%3E-for-Borrowed" class="anchor">§</a><h3 class="code-header">impl&lt;Borrowed&gt; <a class="trait" href="trait.SampleBorrow.html" title="trait rand::distributions::uniform::SampleBorrow">SampleBorrow</a>&lt;Borrowed&gt; for Borrowed<div class="where">where
Borrowed: <a class="trait" href="trait.SampleUniform.html" title="trait rand::distributions::uniform::SampleUniform">SampleUniform</a>,</div></h3></section></div><script src="../../../trait.impl/rand/distributions/uniform/trait.SampleBorrow.js" async></script></section></div></main></body></html>

View file

@ -0,0 +1,10 @@
<!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="Range that supports generating a single sample efficiently."><title>SampleRange in rand::distributions::uniform - 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="#">Sample<wbr>Range</a></h2><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.is_empty" title="is_empty">is_empty</a></li><li><a href="#tymethod.sample_single" title="sample_single">sample_single</a></li></ul><h3><a href="#foreign-impls">Implementations on Foreign Types</a></h3><ul class="block"><li><a href="#impl-SampleRange%3CT%3E-for-Range%3CT%3E" title="Range&#60;T&#62;">Range&#60;T&#62;</a></li><li><a href="#impl-SampleRange%3CT%3E-for-RangeInclusive%3CT%3E" title="RangeInclusive&#60;T&#62;">RangeInclusive&#60;T&#62;</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>distributions::<wbr>uniform</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">distributions</a>::<wbr><a href="index.html">uniform</a></span><h1>Trait <span class="trait">SampleRange</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/distributions/uniform.rs.html#349-355">Source</a> </span></div><pre class="rust item-decl"><code>pub trait SampleRange&lt;T&gt; {
// Required methods
fn <a href="#tymethod.sample_single" class="fn">sample_single</a>&lt;R: <a class="trait" href="../../trait.RngCore.html" title="trait rand::RngCore">RngCore</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>&gt;(self, rng: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;mut R</a>) -&gt; T;
<span class="item-spacer"></span> fn <a href="#tymethod.is_empty" class="fn">is_empty</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.bool.html">bool</a>;
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Range that supports generating a single sample efficiently.</p>
<p>Any type implementing this trait can be used to specify the sampled range
for <code>Rng::gen_range</code>.</p>
</div></details><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.sample_single" class="method"><a class="src rightside" href="../../../src/rand/distributions/uniform.rs.html#351">Source</a><h4 class="code-header">fn <a href="#tymethod.sample_single" class="fn">sample_single</a>&lt;R: <a class="trait" href="../../trait.RngCore.html" title="trait rand::RngCore">RngCore</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>&gt;(self, rng: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;mut R</a>) -&gt; T</h4></section></summary><div class="docblock"><p>Generate a sample from the given range.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.is_empty" class="method"><a class="src rightside" href="../../../src/rand/distributions/uniform.rs.html#354">Source</a><h4 class="code-header">fn <a href="#tymethod.is_empty" class="fn">is_empty</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.bool.html">bool</a></h4></section></summary><div class="docblock"><p>Check whether the range is empty.</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-SampleRange%3CT%3E-for-Range%3CT%3E" class="impl"><a class="src rightside" href="../../../src/rand/distributions/uniform.rs.html#357-367">Source</a><a href="#impl-SampleRange%3CT%3E-for-Range%3CT%3E" class="anchor">§</a><h3 class="code-header">impl&lt;T: <a class="trait" href="trait.SampleUniform.html" title="trait rand::distributions::uniform::SampleUniform">SampleUniform</a> + <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a>&gt; <a class="trait" href="trait.SampleRange.html" title="trait rand::distributions::uniform::SampleRange">SampleRange</a>&lt;T&gt; for <a class="struct" href="https://doc.rust-lang.org/1.84.1/core/ops/range/struct.Range.html" title="struct core::ops::range::Range">Range</a>&lt;T&gt;</h3></section></summary><div class="impl-items"><section id="method.sample_single" class="method trait-impl"><a class="src rightside" href="../../../src/rand/distributions/uniform.rs.html#359-361">Source</a><a href="#method.sample_single" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.sample_single" class="fn">sample_single</a>&lt;R: <a class="trait" href="../../trait.RngCore.html" title="trait rand::RngCore">RngCore</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>&gt;(self, rng: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;mut R</a>) -&gt; T</h4></section><section id="method.is_empty" class="method trait-impl"><a class="src rightside" href="../../../src/rand/distributions/uniform.rs.html#364-366">Source</a><a href="#method.is_empty" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.is_empty" class="fn">is_empty</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.bool.html">bool</a></h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-SampleRange%3CT%3E-for-RangeInclusive%3CT%3E" class="impl"><a class="src rightside" href="../../../src/rand/distributions/uniform.rs.html#369-379">Source</a><a href="#impl-SampleRange%3CT%3E-for-RangeInclusive%3CT%3E" class="anchor">§</a><h3 class="code-header">impl&lt;T: <a class="trait" href="trait.SampleUniform.html" title="trait rand::distributions::uniform::SampleUniform">SampleUniform</a> + <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a>&gt; <a class="trait" href="trait.SampleRange.html" title="trait rand::distributions::uniform::SampleRange">SampleRange</a>&lt;T&gt; for <a class="struct" href="https://doc.rust-lang.org/1.84.1/core/ops/range/struct.RangeInclusive.html" title="struct core::ops::range::RangeInclusive">RangeInclusive</a>&lt;T&gt;</h3></section></summary><div class="impl-items"><section id="method.sample_single-1" class="method trait-impl"><a class="src rightside" href="../../../src/rand/distributions/uniform.rs.html#371-373">Source</a><a href="#method.sample_single-1" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.sample_single" class="fn">sample_single</a>&lt;R: <a class="trait" href="../../trait.RngCore.html" title="trait rand::RngCore">RngCore</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>&gt;(self, rng: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;mut R</a>) -&gt; T</h4></section><section id="method.is_empty-1" class="method trait-impl"><a class="src rightside" href="../../../src/rand/distributions/uniform.rs.html#376-378">Source</a><a href="#method.is_empty-1" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.is_empty" class="fn">is_empty</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.bool.html">bool</a></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/distributions/uniform/trait.SampleRange.js" data-ignore-extern-crates="core" async></script></section></div></main></body></html>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1 @@
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="API documentation for the Rust `alias_method` mod in crate `rand`."><title>rand::distributions::weighted::alias_method - 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 mod"><!--[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="#">Module alias_<wbr>method</a></h2><h3><a href="#structs">Module Items</a></h3><ul class="block"><li><a href="#structs" title="Structs">Structs</a></li><li><a href="#traits" title="Traits">Traits</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="../index.html">In rand::<wbr>distributions::<wbr>weighted</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">distributions</a>::<wbr><a href="../index.html">weighted</a></span><h1>Module <span>alias_method</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/distributions/weighted.rs.html#18">Source</a> </span></div><span class="item-info"><div class="stab deprecated"><span class="emoji">👎</span><span>Deprecated since 0.8.0: moved to rand_distr crate</span></div></span><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="struct" href="struct.WeightedIndex.html" title="struct rand::distributions::weighted::alias_method::WeightedIndex">Weighted<wbr>Index</a><wbr><span class="stab deprecated" title="">Deprecated</span></div></li></ul><h2 id="traits" class="section-header">Traits<a href="#traits" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="trait" href="trait.Weight.html" title="trait rand::distributions::weighted::alias_method::Weight">Weight</a><wbr><span class="stab deprecated" title="">Deprecated</span></div></li></ul></section></div></main></body></html>

View file

@ -0,0 +1 @@
window.SIDEBAR_ITEMS = {"struct":["WeightedIndex"],"trait":["Weight"]};

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,4 @@
<!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="Weighted index sampling"><title>rand::distributions::weighted - 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 mod"><!--[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="#">Module weighted</a></h2><h3><a href="#reexports">Module Items</a></h3><ul class="block"><li><a href="#reexports" title="Re-exports">Re-exports</a></li><li><a href="#modules" title="Modules">Modules</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="../index.html">In rand::<wbr>distributions</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">distributions</a></span><h1>Module <span>weighted</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/distributions/weighted.rs.html#9-47">Source</a> </span></div><span class="item-info"><div class="stab deprecated"><span class="emoji">👎</span><span>Deprecated since 0.8.0: use rand::distributions::{WeightedIndex, WeightedError} instead</span></div></span><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Weighted index sampling</p>
<p>This module is deprecated. Use <a href="../struct.WeightedIndex.html" title="struct rand::distributions::WeightedIndex"><code>crate::distributions::WeightedIndex</code></a> and
<a href="../enum.WeightedError.html" title="enum rand::distributions::WeightedError"><code>crate::distributions::WeightedError</code></a> instead.</p>
</div></details><h2 id="reexports" class="section-header">Re-exports<a href="#reexports" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name" id="reexport.WeightedIndex"><code>pub use super::<a class="struct" href="../struct.WeightedIndex.html" title="struct rand::distributions::WeightedIndex">WeightedIndex</a>;</code></div></li><li><div class="item-name" id="reexport.WeightedError"><code>pub use super::<a class="enum" href="../enum.WeightedError.html" title="enum rand::distributions::WeightedError">WeightedError</a>;</code></div></li></ul><h2 id="modules" class="section-header">Modules<a href="#modules" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="mod" href="alias_method/index.html" title="mod rand::distributions::weighted::alias_method">alias_<wbr>method</a><wbr><span class="stab deprecated" title="">Deprecated</span></div></li></ul></section></div></main></body></html>

View file

@ -0,0 +1 @@
window.SIDEBAR_ITEMS = {"mod":["alias_method"]};

View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../../rand/distributions/enum.WeightedError.html">
<title>Redirection</title>
</head>
<body>
<p>Redirecting to <a href="../../../rand/distributions/enum.WeightedError.html">../../../rand/distributions/enum.WeightedError.html</a>...</p>
<script>location.replace("../../../rand/distributions/enum.WeightedError.html" + location.search + location.hash);</script>
</body>
</html>

View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../../rand/distributions/struct.WeightedIndex.html">
<title>Redirection</title>
</head>
<body>
<p>Redirecting to <a href="../../../rand/distributions/struct.WeightedIndex.html">../../../rand/distributions/struct.WeightedIndex.html</a>...</p>
<script>location.replace("../../../rand/distributions/struct.WeightedIndex.html" + location.search + location.hash);</script>
</body>
</html>

60
rand/fn.random.html Normal file
View file

@ -0,0 +1,60 @@
<!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="Generates a random value using the thread-local random number generator."><title>random in rand - 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 fn"><!--[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="#">random</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#provided-implementations" title="Provided implementations">Provided implementations</a></li><li><a href="#examples" title="Examples">Examples</a></li></ul></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="index.html">In crate rand</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></span><h1>Function <span class="fn">random</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/lib.rs.html#183-186">Source</a> </span></div><pre class="rust item-decl"><code>pub fn random&lt;T&gt;() -&gt; T<div class="where">where
<a class="struct" href="distributions/struct.Standard.html" title="struct rand::distributions::Standard">Standard</a>: <a class="trait" href="distributions/trait.Distribution.html" title="trait rand::distributions::Distribution">Distribution</a>&lt;T&gt;,</div></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Generates a random value using the thread-local random number generator.</p>
<p>This is simply a shortcut for <code>thread_rng().gen()</code>. See <a href="fn.thread_rng.html" title="fn rand::thread_rng"><code>thread_rng</code></a> for
documentation of the entropy source and <a href="distributions/struct.Standard.html" title="struct rand::distributions::Standard"><code>Standard</code></a> for documentation of
distributions and type-specific generation.</p>
<h2 id="provided-implementations"><a class="doc-anchor" href="#provided-implementations">§</a>Provided implementations</h2>
<p>The following types have provided implementations that
generate values with the following ranges and distributions:</p>
<ul>
<li>Integers (<code>i32</code>, <code>u32</code>, <code>isize</code>, <code>usize</code>, etc.): Uniformly distributed
over all values of the type.</li>
<li><code>char</code>: Uniformly distributed over all Unicode scalar values, i.e. all
code points in the range <code>0...0x10_FFFF</code>, except for the range
<code>0xD800...0xDFFF</code> (the surrogate code points). This includes
unassigned/reserved code points.</li>
<li><code>bool</code>: Generates <code>false</code> or <code>true</code>, each with probability 0.5.</li>
<li>Floating point types (<code>f32</code> and <code>f64</code>): Uniformly distributed in the
half-open range <code>[0, 1)</code>. See notes below.</li>
<li>Wrapping integers (<code>Wrapping&lt;T&gt;</code>), besides the type identical to their
normal integer variants.</li>
</ul>
<p>Also supported is the generation of the following
compound types where all component types are supported:</p>
<ul>
<li>Tuples (up to 12 elements): each element is generated sequentially.</li>
<li>Arrays (up to 32 elements): each element is generated sequentially;
see also <a href="trait.Rng.html#method.fill" title="method rand::Rng::fill"><code>Rng::fill</code></a> which supports arbitrary array length for integer
types and tends to be faster for <code>u32</code> and smaller types.</li>
<li><code>Option&lt;T&gt;</code> first generates a <code>bool</code>, and if true generates and returns
<code>Some(value)</code> where <code>value: T</code>, otherwise returning <code>None</code>.</li>
</ul>
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>x = rand::random::&lt;u8&gt;();
<span class="macro">println!</span>(<span class="string">"{}"</span>, x);
<span class="kw">let </span>y = rand::random::&lt;f64&gt;();
<span class="macro">println!</span>(<span class="string">"{}"</span>, y);
<span class="kw">if </span>rand::random() { <span class="comment">// generates a boolean
</span><span class="macro">println!</span>(<span class="string">"Better lucky than good!"</span>);
}</code></pre></div>
<p>If youre calling <code>random()</code> in a loop, caching the generator as in the
following example can increase performance.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>rand::Rng;
<span class="kw">let </span><span class="kw-2">mut </span>v = <span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>];
<span class="kw">for </span>x <span class="kw">in </span>v.iter_mut() {
<span class="kw-2">*</span>x = rand::random()
}
<span class="comment">// can be made faster by caching thread_rng
</span><span class="kw">let </span><span class="kw-2">mut </span>rng = rand::thread_rng();
<span class="kw">for </span>x <span class="kw">in </span>v.iter_mut() {
<span class="kw-2">*</span>x = rng.gen();
}</code></pre></div>
</div></details></section></div></main></body></html>

7
rand/fn.thread_rng.html Normal file
View file

@ -0,0 +1,7 @@
<!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="Retrieve the lazily-initialized thread-local random number generator, seeded by the system. Intended to be used in method chaining style, e.g. `thread_rng().gen::&#60;i32&#62;()`, or cached locally, e.g. `let mut rng = thread_rng();`. Invoked by the `Default` trait, making `ThreadRng::default()` equivalent."><title>thread_rng in rand - 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 fn"><!--[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"><div id="rustdoc-modnav"></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></span><h1>Function <span class="fn">thread_rng</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/rngs/thread.rs.html#88-91">Source</a> </span></div><pre class="rust item-decl"><code>pub fn thread_rng() -&gt; <a class="struct" href="rngs/struct.ThreadRng.html" title="struct rand::rngs::ThreadRng">ThreadRng</a></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Retrieve the lazily-initialized thread-local random number generator,
seeded by the system. Intended to be used in method chaining style,
e.g. <code>thread_rng().gen::&lt;i32&gt;()</code>, or cached locally, e.g.
<code>let mut rng = thread_rng();</code>. Invoked by the <code>Default</code> trait, making
<code>ThreadRng::default()</code> equivalent.</p>
<p>For more information see <a href="rngs/struct.ThreadRng.html" title="struct rand::rngs::ThreadRng"><code>ThreadRng</code></a>.</p>
</div></details></section></div></main></body></html>

32
rand/index.html Normal file
View file

@ -0,0 +1,32 @@
<!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="Utilities for random number generation"><title>rand - 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="../crates.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 mod crate"><!--[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"><ul class="block"><li><a id="all-types" href="all.html">All Items</a></li></ul><section id="rustdoc-toc"><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#quick-start" title="Quick Start">Quick Start</a></li><li><a href="#the-book" title="The Book">The Book</a></li></ul><h3><a href="#modules">Crate Items</a></h3><ul class="block"><li><a href="#modules" title="Modules">Modules</a></li><li><a href="#structs" title="Structs">Structs</a></li><li><a href="#traits" title="Traits">Traits</a></li><li><a href="#functions" title="Functions">Functions</a></li></ul></section><div id="rustdoc-modnav"></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"><h1>Crate <span>rand</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/lib.rs.html#10-214">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Utilities for random number generation</p>
<p>Rand provides utilities to generate random numbers, to convert them to
useful types and distributions, and some randomness-related algorithms.</p>
<h2 id="quick-start"><a class="doc-anchor" href="#quick-start">§</a>Quick Start</h2>
<p>To get you started quickly, the easiest and highest-level way to get
a random value is to use <a href="fn.random.html" title="fn rand::random"><code>random()</code></a>; alternatively you can use
<a href="fn.thread_rng.html" title="fn rand::thread_rng"><code>thread_rng()</code></a>. The <a href="trait.Rng.html" title="trait rand::Rng"><code>Rng</code></a> trait provides a useful API on all RNGs, while
the <a href="distributions/index.html" title="mod rand::distributions"><code>distributions</code></a> and <a href="seq/index.html" title="mod rand::seq"><code>seq</code></a> modules provide further
functionality on top of RNGs.</p>
<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">if </span>rand::random() { <span class="comment">// generates a boolean
// Try printing a random unicode code point (probably a bad idea)!
</span><span class="macro">println!</span>(<span class="string">"char: {}"</span>, rand::random::&lt;char&gt;());
}
<span class="kw">let </span><span class="kw-2">mut </span>rng = rand::thread_rng();
<span class="kw">let </span>y: f64 = rng.gen(); <span class="comment">// generates a float between 0 and 1
</span><span class="kw">let </span><span class="kw-2">mut </span>nums: Vec&lt;i32&gt; = (<span class="number">1</span>..<span class="number">100</span>).collect();
nums.shuffle(<span class="kw-2">&amp;mut </span>rng);</code></pre></div>
<h2 id="the-book"><a class="doc-anchor" href="#the-book">§</a>The Book</h2>
<p>For the user guide and further documentation, please read
<a href="https://rust-random.github.io/book">The Rust Rand Book</a>.</p>
</div></details><h2 id="modules" class="section-header">Modules<a href="#modules" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="mod" href="distributions/index.html" title="mod rand::distributions">distributions</a></div><div class="desc docblock-short">Generating random samples from probability distributions</div></li><li><div class="item-name"><a class="mod" href="prelude/index.html" title="mod rand::prelude">prelude</a></div><div class="desc docblock-short">Convenience re-export of common members</div></li><li><div class="item-name"><a class="mod" href="rngs/index.html" title="mod rand::rngs">rngs</a></div><div class="desc docblock-short">Random number generators and adapters</div></li><li><div class="item-name"><a class="mod" href="seq/index.html" title="mod rand::seq">seq</a></div><div class="desc docblock-short">Sequence-related functionality</div></li></ul><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="struct" href="struct.Error.html" title="struct rand::Error">Error</a></div><div class="desc docblock-short">Error type of random number generators</div></li></ul><h2 id="traits" class="section-header">Traits<a href="#traits" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="trait" href="trait.CryptoRng.html" title="trait rand::CryptoRng">Crypto<wbr>Rng</a></div><div class="desc docblock-short">A marker trait used to indicate that an <a href="trait.RngCore.html" title="trait rand::RngCore"><code>RngCore</code></a> or <a href="../rand_core/block/trait.BlockRngCore.html" title="trait rand_core::block::BlockRngCore"><code>BlockRngCore</code></a>
implementation is supposed to be cryptographically secure.</div></li><li><div class="item-name"><a class="trait" href="trait.Fill.html" title="trait rand::Fill">Fill</a></div><div class="desc docblock-short">Types which may be filled with random data</div></li><li><div class="item-name"><a class="trait" href="trait.Rng.html" title="trait rand::Rng">Rng</a></div><div class="desc docblock-short">An automatically-implemented extension trait on <a href="trait.RngCore.html" title="trait rand::RngCore"><code>RngCore</code></a> providing high-level
generic methods for sampling values and other convenience methods.</div></li><li><div class="item-name"><a class="trait" href="trait.RngCore.html" title="trait rand::RngCore">RngCore</a></div><div class="desc docblock-short">The core of a random number generator.</div></li><li><div class="item-name"><a class="trait" href="trait.SeedableRng.html" title="trait rand::SeedableRng">Seedable<wbr>Rng</a></div><div class="desc docblock-short">A random number generator that can be explicitly seeded.</div></li></ul><h2 id="functions" class="section-header">Functions<a href="#functions" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="fn" href="fn.random.html" title="fn rand::random">random</a></div><div class="desc docblock-short">Generates a random value using the thread-local random number generator.</div></li><li><div class="item-name"><a class="fn" href="fn.thread_rng.html" title="fn rand::thread_rng">thread_<wbr>rng</a></div><div class="desc docblock-short">Retrieve the lazily-initialized thread-local random number generator,
seeded by the system. Intended to be used in method chaining style,
e.g. <code>thread_rng().gen::&lt;i32&gt;()</code>, or cached locally, e.g.
<code>let mut rng = thread_rng();</code>. Invoked by the <code>Default</code> trait, making
<code>ThreadRng::default()</code> equivalent.</div></li></ul></section></div></main></body></html>

7
rand/prelude/index.html Normal file
View file

@ -0,0 +1,7 @@
<!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="Convenience re-export of common members"><title>rand::prelude - 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 mod"><!--[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="#">Module prelude</a></h2><h3><a href="#reexports">Module Items</a></h3><ul class="block"><li><a href="#reexports" title="Re-exports">Re-exports</a></li></ul></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="../index.html">In crate rand</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></span><h1>Module <span>prelude</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/prelude.rs.html#9-34">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Convenience re-export of common members</p>
<p>Like the standard librarys prelude, this module simplifies importing of
common items. Unlike the standard prelude, the contents of this module must
be imported manually:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>rand::prelude::<span class="kw-2">*</span>;</code></pre></div>
</div></details><h2 id="reexports" class="section-header">Re-exports<a href="#reexports" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name" id="reexport.Distribution"><code>pub use crate::distributions::<a class="trait" href="../distributions/trait.Distribution.html" title="trait rand::distributions::Distribution">Distribution</a>;</code></div></li><li><div class="item-name" id="reexport.StdRng"><code>pub use crate::rngs::<a class="struct" href="../rngs/struct.StdRng.html" title="struct rand::rngs::StdRng">StdRng</a>;</code></div></li><li><div class="item-name" id="reexport.ThreadRng"><code>pub use crate::rngs::<a class="struct" href="../rngs/struct.ThreadRng.html" title="struct rand::rngs::ThreadRng">ThreadRng</a>;</code></div></li><li><div class="item-name" id="reexport.IteratorRandom"><code>pub use crate::seq::<a class="trait" href="../seq/trait.IteratorRandom.html" title="trait rand::seq::IteratorRandom">IteratorRandom</a>;</code></div></li><li><div class="item-name" id="reexport.SliceRandom"><code>pub use crate::seq::<a class="trait" href="../seq/trait.SliceRandom.html" title="trait rand::seq::SliceRandom">SliceRandom</a>;</code></div></li><li><div class="item-name" id="reexport.random"><code>pub use crate::<a class="fn" href="../fn.random.html" title="fn rand::random">random</a>;</code></div></li><li><div class="item-name" id="reexport.thread_rng"><code>pub use crate::<a class="fn" href="../fn.thread_rng.html" title="fn rand::thread_rng">thread_rng</a>;</code></div></li><li><div class="item-name" id="reexport.CryptoRng"><code>pub use crate::<a class="trait" href="../trait.CryptoRng.html" title="trait rand::CryptoRng">CryptoRng</a>;</code></div></li><li><div class="item-name" id="reexport.Rng"><code>pub use crate::<a class="trait" href="../trait.Rng.html" title="trait rand::Rng">Rng</a>;</code></div></li><li><div class="item-name" id="reexport.RngCore"><code>pub use crate::<a class="trait" href="../trait.RngCore.html" title="trait rand::RngCore">RngCore</a>;</code></div></li><li><div class="item-name" id="reexport.SeedableRng"><code>pub use crate::<a class="trait" href="../trait.SeedableRng.html" title="trait rand::SeedableRng">SeedableRng</a>;</code></div></li></ul></section></div></main></body></html>

View file

@ -0,0 +1 @@
window.SIDEBAR_ITEMS = {};

11
rand/rng/trait.Fill.html Normal file
View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../rand/trait.Fill.html">
<title>Redirection</title>
</head>
<body>
<p>Redirecting to <a href="../../rand/trait.Fill.html">../../rand/trait.Fill.html</a>...</p>
<script>location.replace("../../rand/trait.Fill.html" + location.search + location.hash);</script>
</body>
</html>

11
rand/rng/trait.Rng.html Normal file
View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../rand/trait.Rng.html">
<title>Redirection</title>
</head>
<body>
<p>Redirecting to <a href="../../rand/trait.Rng.html">../../rand/trait.Rng.html</a>...</p>
<script>location.replace("../../rand/trait.Rng.html" + location.search + location.hash);</script>
</body>
</html>

View file

@ -0,0 +1,4 @@
<!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="Wrappers / adapters forming RNGs"><title>rand::rngs::adapter - 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 mod"><!--[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="#">Module adapter</a></h2><h3><a href="#structs">Module Items</a></h3><ul class="block"><li><a href="#structs" title="Structs">Structs</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="../index.html">In rand::<wbr>rngs</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">rngs</a></span><h1>Module <span>adapter</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/rngs/adapter/mod.rs.html#9-16">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Wrappers / adapters forming RNGs</p>
</div></details><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="struct" href="struct.ReadError.html" title="struct rand::rngs::adapter::ReadError">Read<wbr>Error</a><wbr><span class="stab deprecated" title="">Deprecated</span></div><div class="desc docblock-short"><code>ReadRng</code> error type</div></li><li><div class="item-name"><a class="struct" href="struct.ReadRng.html" title="struct rand::rngs::adapter::ReadRng">ReadRng</a><wbr><span class="stab deprecated" title="">Deprecated</span></div><div class="desc docblock-short">An RNG that reads random bytes straight from any type supporting
<a href="https://doc.rust-lang.org/1.84.1/std/io/trait.Read.html" title="trait std::io::Read"><code>std::io::Read</code></a>, for example files.</div></li><li><div class="item-name"><a class="struct" href="struct.ReseedingRng.html" title="struct rand::rngs::adapter::ReseedingRng">Reseeding<wbr>Rng</a></div><div class="desc docblock-short">A wrapper around any PRNG that implements <a href="../../../rand_core/block/trait.BlockRngCore.html" title="trait rand_core::block::BlockRngCore"><code>BlockRngCore</code></a>, that adds the
ability to reseed it.</div></li></ul></section></div></main></body></html>

View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../../../rand/rngs/adapter/struct.ReadError.html">
<title>Redirection</title>
</head>
<body>
<p>Redirecting to <a href="../../../../rand/rngs/adapter/struct.ReadError.html">../../../../rand/rngs/adapter/struct.ReadError.html</a>...</p>
<script>location.replace("../../../../rand/rngs/adapter/struct.ReadError.html" + location.search + location.hash);</script>
</body>
</html>

View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../../../rand/rngs/adapter/struct.ReadRng.html">
<title>Redirection</title>
</head>
<body>
<p>Redirecting to <a href="../../../../rand/rngs/adapter/struct.ReadRng.html">../../../../rand/rngs/adapter/struct.ReadRng.html</a>...</p>
<script>location.replace("../../../../rand/rngs/adapter/struct.ReadRng.html" + location.search + location.hash);</script>
</body>
</html>

View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../../../rand/rngs/adapter/struct.ReseedingRng.html">
<title>Redirection</title>
</head>
<body>
<p>Redirecting to <a href="../../../../rand/rngs/adapter/struct.ReseedingRng.html">../../../../rand/rngs/adapter/struct.ReseedingRng.html</a>...</p>
<script>location.replace("../../../../rand/rngs/adapter/struct.ReseedingRng.html" + location.search + location.hash);</script>
</body>
</html>

View file

@ -0,0 +1 @@
window.SIDEBAR_ITEMS = {"struct":["ReadError","ReadRng","ReseedingRng"]};

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

72
rand/rngs/index.html Normal file
View file

@ -0,0 +1,72 @@
<!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="Random number generators and adapters"><title>rand::rngs - 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 mod"><!--[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="#">Module rngs</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#background-random-number-generators-rngs" title="Background: Random number generators (RNGs)">Background: Random number generators (RNGs)</a></li><li><a href="#traits-and-functionality" title="Traits and functionality">Traits and functionality</a></li><li><a href="#our-generators" title="Our generators">Our generators</a></li><li><a href="#additional-generators" title="Additional generators">Additional generators</a></li></ul><h3><a href="#modules">Module Items</a></h3><ul class="block"><li><a href="#modules" title="Modules">Modules</a></li><li><a href="#structs" title="Structs">Structs</a></li></ul></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="../index.html">In crate rand</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></span><h1>Module <span>rngs</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/rngs/mod.rs.html#9-119">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Random number generators and adapters</p>
<h3 id="background-random-number-generators-rngs"><a class="doc-anchor" href="#background-random-number-generators-rngs">§</a>Background: Random number generators (RNGs)</h3>
<p>Computers cannot produce random numbers from nowhere. We classify
random number generators as follows:</p>
<ul>
<li>“True” random number generators (TRNGs) use hard-to-predict data sources
(e.g. the high-resolution parts of event timings and sensor jitter) to
harvest random bit-sequences, apply algorithms to remove bias and
estimate available entropy, then combine these bits into a byte-sequence
or an entropy pool. This job is usually done by the operating system or
a hardware generator (HRNG).</li>
<li>“Pseudo”-random number generators (PRNGs) use algorithms to transform a
seed into a sequence of pseudo-random numbers. These generators can be
fast and produce well-distributed unpredictable random numbers (or not).
They are usually deterministic: given algorithm and seed, the output
sequence can be reproduced. They have finite period and eventually loop;
with many algorithms this period is fixed and can be proven sufficiently
long, while others are chaotic and the period depends on the seed.</li>
<li>“Cryptographically secure” pseudo-random number generators (CSPRNGs)
are the sub-set of PRNGs which are secure. Security of the generator
relies both on hiding the internal state and using a strong algorithm.</li>
</ul>
<h3 id="traits-and-functionality"><a class="doc-anchor" href="#traits-and-functionality">§</a>Traits and functionality</h3>
<p>All RNGs implement the <a href="../trait.RngCore.html" title="trait rand::RngCore"><code>RngCore</code></a> trait, as a consequence of which the
<a href="../trait.Rng.html" title="trait rand::Rng"><code>Rng</code></a> extension trait is automatically implemented. Secure RNGs may
additionally implement the <a href="../trait.CryptoRng.html" title="trait rand::CryptoRng"><code>CryptoRng</code></a> trait.</p>
<p>All PRNGs require a seed to produce their random number sequence. The
<a href="../trait.SeedableRng.html" title="trait rand::SeedableRng"><code>SeedableRng</code></a> trait provides three ways of constructing PRNGs:</p>
<ul>
<li><code>from_seed</code> accepts a type specific to the PRNG</li>
<li><code>from_rng</code> allows a PRNG to be seeded from any other RNG</li>
<li><code>seed_from_u64</code> allows any PRNG to be seeded from a <code>u64</code> insecurely</li>
<li><code>from_entropy</code> securely seeds a PRNG from fresh entropy</li>
</ul>
<p>Use the <a href="../../rand_core/index.html" title="mod rand_core"><code>rand_core</code></a> crate when implementing your own RNGs.</p>
<h3 id="our-generators"><a class="doc-anchor" href="#our-generators">§</a>Our generators</h3>
<p>This crate provides several random number generators:</p>
<ul>
<li><a href="struct.OsRng.html" title="struct rand::rngs::OsRng"><code>OsRng</code></a> is an interface to the operating systems random number
source. Typically the operating system uses a CSPRNG with entropy
provided by a TRNG and some type of on-going re-seeding.</li>
<li><a href="struct.ThreadRng.html" title="struct rand::rngs::ThreadRng"><code>ThreadRng</code></a>, provided by the <a href="../fn.thread_rng.html" title="fn rand::thread_rng"><code>thread_rng</code></a> function, is a handle to a
thread-local CSPRNG with periodic seeding from <a href="struct.OsRng.html" title="struct rand::rngs::OsRng"><code>OsRng</code></a>. Because this
is local, it is typically much faster than <a href="struct.OsRng.html" title="struct rand::rngs::OsRng"><code>OsRng</code></a>. It should be
secure, though the paranoid may prefer <a href="struct.OsRng.html" title="struct rand::rngs::OsRng"><code>OsRng</code></a>.</li>
<li><a href="struct.StdRng.html" title="struct rand::rngs::StdRng"><code>StdRng</code></a> is a CSPRNG chosen for good performance and trust of security
(based on reviews, maturity and usage). The current algorithm is ChaCha12,
which is well established and rigorously analysed.
<a href="struct.StdRng.html" title="struct rand::rngs::StdRng"><code>StdRng</code></a> provides the algorithm used by <a href="struct.ThreadRng.html" title="struct rand::rngs::ThreadRng"><code>ThreadRng</code></a> but without
periodic reseeding.</li>
<li>[<code>SmallRng</code>] is an <strong>insecure</strong> PRNG designed to be fast, simple, require
little memory, and have good output quality.</li>
</ul>
<p>The algorithms selected for <a href="struct.StdRng.html" title="struct rand::rngs::StdRng"><code>StdRng</code></a> and [<code>SmallRng</code>] may change in any
release and may be platform-dependent, therefore they should be considered
<strong>not reproducible</strong>.</p>
<h3 id="additional-generators"><a class="doc-anchor" href="#additional-generators">§</a>Additional generators</h3>
<p><strong>TRNGs</strong>: The <a href="https://crates.io/crates/rdrand"><code>rdrand</code></a> crate provides an interface to the RDRAND and
RDSEED instructions available in modern Intel and AMD CPUs.
The <a href="https://crates.io/crates/rand_jitter"><code>rand_jitter</code></a> crate provides a user-space implementation of
entropy harvesting from CPU timer jitter, but is very slow and has
<a href="https://github.com/rust-random/rand/issues/699">security issues</a>.</p>
<p><strong>PRNGs</strong>: Several companion crates are available, providing individual or
families of PRNG algorithms. These provide the implementations behind
<a href="struct.StdRng.html" title="struct rand::rngs::StdRng"><code>StdRng</code></a> and [<code>SmallRng</code>] but can also be used directly, indeed <em>should</em>
be used directly when <strong>reproducibility</strong> matters.
Some suggestions are: <a href="https://crates.io/crates/rand_chacha"><code>rand_chacha</code></a>, <a href="https://crates.io/crates/rand_pcg"><code>rand_pcg</code></a>, <a href="https://crates.io/crates/rand_xoshiro"><code>rand_xoshiro</code></a>.
A full list can be found by searching for crates with the <a href="https://crates.io/keywords/rng"><code>rng</code> tag</a>.</p>
</div></details><h2 id="modules" class="section-header">Modules<a href="#modules" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="mod" href="adapter/index.html" title="mod rand::rngs::adapter">adapter</a></div><div class="desc docblock-short">Wrappers / adapters forming RNGs</div></li><li><div class="item-name"><a class="mod" href="mock/index.html" title="mod rand::rngs::mock">mock</a></div><div class="desc docblock-short">Mock random number generator</div></li></ul><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="struct" href="struct.OsRng.html" title="struct rand::rngs::OsRng">OsRng</a></div><div class="desc docblock-short">A random number generator that retrieves randomness from the
operating system.</div></li><li><div class="item-name"><a class="struct" href="struct.StdRng.html" title="struct rand::rngs::StdRng">StdRng</a></div><div class="desc docblock-short">The standard RNG. The PRNG algorithm in <code>StdRng</code> is chosen to be efficient
on the current platform, to be statistically strong and unpredictable
(meaning a cryptographically secure PRNG).</div></li><li><div class="item-name"><a class="struct" href="struct.ThreadRng.html" title="struct rand::rngs::ThreadRng">Thread<wbr>Rng</a></div><div class="desc docblock-short">A reference to the thread-local generator</div></li></ul></section></div></main></body></html>

View file

@ -0,0 +1,2 @@
<!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="Mock random number generator"><title>rand::rngs::mock - 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 mod"><!--[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="#">Module mock</a></h2><h3><a href="#structs">Module Items</a></h3><ul class="block"><li><a href="#structs" title="Structs">Structs</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="../index.html">In rand::<wbr>rngs</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">rngs</a></span><h1>Module <span>mock</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/rngs/mock.rs.html#9-87">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Mock random number generator</p>
</div></details><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="struct" href="struct.StepRng.html" title="struct rand::rngs::mock::StepRng">StepRng</a></div><div class="desc docblock-short">A simple implementation of <code>RngCore</code> for testing purposes.</div></li></ul></section></div></main></body></html>

View file

@ -0,0 +1 @@
window.SIDEBAR_ITEMS = {"struct":["StepRng"]};

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1 @@
window.SIDEBAR_ITEMS = {"mod":["adapter","mock"],"struct":["OsRng","StdRng","ThreadRng"]};

View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../../rand/rngs/struct.StdRng.html">
<title>Redirection</title>
</head>
<body>
<p>Redirecting to <a href="../../../rand/rngs/struct.StdRng.html">../../../rand/rngs/struct.StdRng.html</a>...</p>
<script>location.replace("../../../rand/rngs/struct.StdRng.html" + location.search + location.hash);</script>
</body>
</html>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../../rand/fn.thread_rng.html">
<title>Redirection</title>
</head>
<body>
<p>Redirecting to <a href="../../../rand/fn.thread_rng.html">../../../rand/fn.thread_rng.html</a>...</p>
<script>location.replace("../../../rand/fn.thread_rng.html" + location.search + location.hash);</script>
</body>
</html>

View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../../rand/rngs/struct.ThreadRng.html">
<title>Redirection</title>
</head>
<body>
<p>Redirecting to <a href="../../../rand/rngs/struct.ThreadRng.html">../../../rand/rngs/struct.ThreadRng.html</a>...</p>
<script>location.replace("../../../rand/rngs/struct.ThreadRng.html" + location.search + location.hash);</script>
</body>
</html>

17
rand/seq/index.html Normal file
View file

@ -0,0 +1,17 @@
<!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="Sequence-related functionality"><title>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 mod"><!--[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="#">Module seq</a></h2><h3><a href="#modules">Module Items</a></h3><ul class="block"><li><a href="#modules" title="Modules">Modules</a></li><li><a href="#structs" title="Structs">Structs</a></li><li><a href="#traits" title="Traits">Traits</a></li></ul></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="../index.html">In crate rand</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></span><h1>Module <span>seq</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#9-1356">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Sequence-related functionality</p>
<p>This module provides:</p>
<ul>
<li><a href="trait.SliceRandom.html" title="trait rand::seq::SliceRandom"><code>SliceRandom</code></a> slice sampling and mutation</li>
<li><a href="trait.IteratorRandom.html" title="trait rand::seq::IteratorRandom"><code>IteratorRandom</code></a> iterator sampling</li>
<li><a href="index/fn.sample.html" title="fn rand::seq::index::sample"><code>index::sample</code></a> low-level API to choose multiple indices from
<code>0..length</code></li>
</ul>
<p>Also see:</p>
<ul>
<li><a href="../distributions/struct.WeightedIndex.html" title="struct rand::distributions::WeightedIndex"><code>crate::distributions::WeightedIndex</code></a> distribution which provides
weighted index sampling.</li>
</ul>
<p>In order to make results reproducible across 32-64 bit architectures, all
<code>usize</code> indices are sampled as a <code>u32</code> where possible (also providing a
small performance boost in some cases).</p>
</div></details><h2 id="modules" class="section-header">Modules<a href="#modules" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="mod" href="index/index.html" title="mod rand::seq::index">index</a></div><div class="desc docblock-short">Low-level API for sampling indices</div></li></ul><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="struct" href="struct.SliceChooseIter.html" title="struct rand::seq::SliceChooseIter">Slice<wbr>Choose<wbr>Iter</a></div><div class="desc docblock-short">An iterator over multiple slice elements.</div></li></ul><h2 id="traits" class="section-header">Traits<a href="#traits" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="trait" href="trait.IteratorRandom.html" title="trait rand::seq::IteratorRandom">Iterator<wbr>Random</a></div><div class="desc docblock-short">Extension trait on iterators, providing random sampling methods.</div></li><li><div class="item-name"><a class="trait" href="trait.SliceRandom.html" title="trait rand::seq::SliceRandom">Slice<wbr>Random</a></div><div class="desc docblock-short">Extension trait on slices, providing random mutation and sampling methods.</div></li></ul></section></div></main></body></html>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,19 @@
<!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="Randomly sample exactly `amount` distinct indices from `0..length`, and return them in random order (fully shuffled)."><title>sample in rand::seq::index - 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 fn"><!--[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"><div id="rustdoc-modnav"><h2><a href="index.html">In rand::<wbr>seq::<wbr>index</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>::<wbr><a href="index.html">index</a></span><h1>Function <span class="fn">sample</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/index.rs.html#222-259">Source</a> </span></div><pre class="rust item-decl"><code>pub fn sample&lt;R&gt;(rng: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;mut R</a>, length: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.usize.html">usize</a>, amount: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.usize.html">usize</a>) -&gt; <a class="enum" href="enum.IndexVec.html" title="enum rand::seq::index::IndexVec">IndexVec</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></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Randomly sample exactly <code>amount</code> distinct indices from <code>0..length</code>, and
return them in random order (fully shuffled).</p>
<p>This method is used internally by the slice sampling methods, but it can
sometimes be useful to have the indices themselves so this is provided as
an alternative.</p>
<p>The implementation used is not specified; we automatically select the
fastest available algorithm for the <code>length</code> and <code>amount</code> parameters
(based on detailed profiling on an Intel Haswell CPU). Roughly speaking,
complexity is <code>O(amount)</code>, except that when <code>amount</code> is small, performance
is closer to <code>O(amount^2)</code>, and when <code>length</code> is close to <code>amount</code> then
<code>O(length)</code>.</p>
<p>Note that performance is significantly better over <code>u32</code> indices than over
<code>u64</code> indices. Because of this we hide the underlying type behind an
abstraction, <code>IndexVec</code>.</p>
<p>If an allocation-free <code>no_std</code> function is required, it is suggested
to adapt the internal <code>sample_floyd</code> implementation.</p>
<p>Panics if <code>amount &gt; length</code>.</p>
</div></details></section></div></main></body></html>

View file

@ -0,0 +1,20 @@
<!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="Randomly sample exactly `amount` distinct indices from `0..length`, and return them in an arbitrary order (there is no guarantee of shuffling or ordering). The weights are to be provided by the input function `weights`, which will be called once for each index."><title>sample_weighted in rand::seq::index - 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 fn"><!--[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"><div id="rustdoc-modnav"><h2><a href="index.html">In rand::<wbr>seq::<wbr>index</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>::<wbr><a href="index.html">index</a></span><h1>Function <span class="fn">sample_weighted</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/index.rs.html#277-293">Source</a> </span></div><pre class="rust item-decl"><code>pub fn sample_weighted&lt;R, F, X&gt;(
rng: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;mut R</a>,
length: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.usize.html">usize</a>,
weight: F,
amount: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.usize.html">usize</a>,
) -&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="enum" href="enum.IndexVec.html" title="enum rand::seq::index::IndexVec">IndexVec</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>(<a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.usize.html">usize</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></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Randomly sample exactly <code>amount</code> distinct indices from <code>0..length</code>, and
return them in an arbitrary order (there is no guarantee of shuffling or
ordering). The weights are to be provided by the input function <code>weights</code>,
which will be called once for each index.</p>
<p>This method is used internally by the slice sampling methods, but it can
sometimes be useful to have the indices themselves so this is provided as
an alternative.</p>
<p>This implementation uses <code>O(length + amount)</code> space and <code>O(length)</code> time
if the “nightly” feature is enabled, or <code>O(length)</code> space and
<code>O(length + amount * log length)</code> time otherwise.</p>
<p>Panics if <code>amount &gt; length</code>.</p>
</div></details></section></div></main></body></html>

View file

@ -0,0 +1,6 @@
<!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="Low-level API for sampling indices"><title>rand::seq::index - 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 mod"><!--[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="#">Module index</a></h2><h3><a href="#enums">Module Items</a></h3><ul class="block"><li><a href="#enums" title="Enums">Enums</a></li><li><a href="#functions" title="Functions">Functions</a></li></ul></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>Module <span>index</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/index.rs.html#9-678">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Low-level API for sampling indices</p>
</div></details><h2 id="enums" class="section-header">Enums<a href="#enums" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="enum" href="enum.IndexVec.html" title="enum rand::seq::index::IndexVec">Index<wbr>Vec</a></div><div class="desc docblock-short">A vector of indices.</div></li><li><div class="item-name"><a class="enum" href="enum.IndexVecIntoIter.html" title="enum rand::seq::index::IndexVecIntoIter">Index<wbr>VecInto<wbr>Iter</a></div><div class="desc docblock-short">Return type of <code>IndexVec::into_iter</code>.</div></li><li><div class="item-name"><a class="enum" href="enum.IndexVecIter.html" title="enum rand::seq::index::IndexVecIter">Index<wbr>VecIter</a></div><div class="desc docblock-short">Return type of <code>IndexVec::iter</code>.</div></li></ul><h2 id="functions" class="section-header">Functions<a href="#functions" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="fn" href="fn.sample.html" title="fn rand::seq::index::sample">sample</a></div><div class="desc docblock-short">Randomly sample exactly <code>amount</code> distinct indices from <code>0..length</code>, and
return them in random order (fully shuffled).</div></li><li><div class="item-name"><a class="fn" href="fn.sample_weighted.html" title="fn rand::seq::index::sample_weighted">sample_<wbr>weighted</a></div><div class="desc docblock-short">Randomly sample exactly <code>amount</code> distinct indices from <code>0..length</code>, and
return them in an arbitrary order (there is no guarantee of shuffling or
ordering). The weights are to be provided by the input function <code>weights</code>,
which will be called once for each index.</div></li></ul></section></div></main></body></html>

View file

@ -0,0 +1 @@
window.SIDEBAR_ITEMS = {"enum":["IndexVec","IndexVecIntoIter","IndexVecIter"],"fn":["sample","sample_weighted"]};

View file

@ -0,0 +1 @@
window.SIDEBAR_ITEMS = {"mod":["index"],"struct":["SliceChooseIter"],"trait":["IteratorRandom","SliceRandom"]};

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,77 @@
<!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 iterators, providing random sampling methods."><title>IteratorRandom 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="#">Iterator<wbr>Random</a></h2><h3><a href="#provided-methods">Provided Methods</a></h3><ul class="block"><li><a href="#method.choose" title="choose">choose</a></li><li><a href="#method.choose_multiple" title="choose_multiple">choose_multiple</a></li><li><a href="#method.choose_multiple_fill" title="choose_multiple_fill">choose_multiple_fill</a></li><li><a href="#method.choose_stable" title="choose_stable">choose_stable</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">IteratorRandom</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#288-489">Source</a> </span></div><pre class="rust item-decl"><code>pub trait IteratorRandom: <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> + <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> {
// Provided methods
fn <a href="#method.choose" class="fn">choose</a>&lt;R&gt;(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;Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.84.1/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::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="#method.choose_stable" class="fn">choose_stable</a>&lt;R&gt;(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;Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.84.1/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::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="#method.choose_multiple_fill" class="fn">choose_multiple_fill</a>&lt;R&gt;(
self,
rng: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;mut R</a>,
buf: &amp;mut [Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.84.1/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>],
) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.usize.html">usize</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="#method.choose_multiple" class="fn">choose_multiple</a>&lt;R&gt;(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="https://doc.rust-lang.org/1.84.1/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a>&lt;Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.84.1/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::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> { ... }
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Extension trait on iterators, providing random sampling methods.</p>
<p>This trait is implemented on all iterators <code>I</code> where <code>I: Iterator + Sized</code>
and provides methods for
choosing one or more 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::IteratorRandom;
<span class="kw">let </span><span class="kw-2">mut </span>rng = rand::thread_rng();
<span class="kw">let </span>faces = <span class="string">"😀😎😐😕😠😢"</span>;
<span class="macro">println!</span>(<span class="string">"I am {}!"</span>, faces.chars().choose(<span class="kw-2">&amp;mut </span>rng).unwrap());</code></pre></div>
<p>Example output (non-deterministic):</p>
<div class="example-wrap"><pre class="language-none"><code>I am 😀!</code></pre></div></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" class="method"><a class="src rightside" href="../../src/rand/seq/mod.rs.html#304-353">Source</a><h4 class="code-header">fn <a href="#method.choose" class="fn">choose</a>&lt;R&gt;(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;Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.84.1/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::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>Choose one element at random from the iterator.</p>
<p>Returns <code>None</code> if and only if the iterator is empty.</p>
<p>This method uses <a href="https://doc.rust-lang.org/1.84.1/core/iter/traits/iterator/trait.Iterator.html#method.size_hint" title="method core::iter::traits::iterator::Iterator::size_hint"><code>Iterator::size_hint</code></a> for optimisation. With an
accurate hint and where <a href="https://doc.rust-lang.org/1.84.1/core/iter/traits/iterator/trait.Iterator.html#method.nth" title="method core::iter::traits::iterator::Iterator::nth"><code>Iterator::nth</code></a> is a constant-time operation
this method can offer <code>O(1)</code> performance. Where no size hint is
available, complexity is <code>O(n)</code> where <code>n</code> is the iterator length.
Partial hints (where <code>lower &gt; 0</code>) also improve performance.</p>
<p>Note that the output values and the number of RNG samples used
depends on size hints. In particular, <code>Iterator</code> combinators that dont
change the values yielded but change the size hints may result in
<code>choose</code> returning different elements. If you want consistent results
and RNG usage consider using <a href="trait.IteratorRandom.html#method.choose_stable" title="method rand::seq::IteratorRandom::choose_stable"><code>IteratorRandom::choose_stable</code></a>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.choose_stable" class="method"><a class="src rightside" href="../../src/rand/seq/mod.rs.html#373-411">Source</a><h4 class="code-header">fn <a href="#method.choose_stable" class="fn">choose_stable</a>&lt;R&gt;(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;Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.84.1/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::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>Choose one element at random from the iterator.</p>
<p>Returns <code>None</code> if and only if the iterator is empty.</p>
<p>This method is very similar to <a href="trait.IteratorRandom.html#method.choose" title="method rand::seq::IteratorRandom::choose"><code>choose</code></a> except that the result
only depends on the length of the iterator and the values produced by
<code>rng</code>. Notably for any iterator of a given length this will make the
same requests to <code>rng</code> and if the same sequence of values are produced
the same index will be selected from <code>self</code>. This may be useful if you
need consistent results no matter what type of iterator you are working
with. If you do not need this stability prefer <a href="trait.IteratorRandom.html#method.choose" title="method rand::seq::IteratorRandom::choose"><code>choose</code></a>.</p>
<p>Note that this method still uses <a href="https://doc.rust-lang.org/1.84.1/core/iter/traits/iterator/trait.Iterator.html#method.size_hint" title="method core::iter::traits::iterator::Iterator::size_hint"><code>Iterator::size_hint</code></a> to skip
constructing elements where possible, however the selection and <code>rng</code>
calls are the same in the face of this optimization. If you want to
force every element to be created regardless call <code>.inspect(|e| ())</code>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.choose_multiple_fill" class="method"><a class="src rightside" href="../../src/rand/seq/mod.rs.html#426-448">Source</a><h4 class="code-header">fn <a href="#method.choose_multiple_fill" class="fn">choose_multiple_fill</a>&lt;R&gt;(self, rng: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;mut R</a>, buf: &amp;mut [Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.84.1/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::Item">Item</a>]) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.usize.html">usize</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>Collects values at random from the iterator into a supplied buffer
until that buffer is filled.</p>
<p>Although the elements are selected randomly, the order of elements in
the buffer is neither stable nor fully random. If random ordering is
desired, shuffle the result.</p>
<p>Returns the number of elements added to the buffer. This equals the length
of the buffer unless the iterator contains insufficient elements, in which
case this equals the number of elements available.</p>
<p>Complexity is <code>O(n)</code> where <code>n</code> is the length of the iterator.
For slices, prefer <a href="trait.SliceRandom.html#tymethod.choose_multiple" title="method rand::seq::SliceRandom::choose_multiple"><code>SliceRandom::choose_multiple</code></a>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.choose_multiple" class="method"><a class="src rightside" href="../../src/rand/seq/mod.rs.html#466-488">Source</a><h4 class="code-header">fn <a href="#method.choose_multiple" class="fn">choose_multiple</a>&lt;R&gt;(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="https://doc.rust-lang.org/1.84.1/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a>&lt;Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.84.1/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::traits::iterator::Iterator::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>Collects <code>amount</code> values at random from the iterator into a vector.</p>
<p>This is equivalent to <code>choose_multiple_fill</code> except for the result type.</p>
<p>Although the elements are selected randomly, the order of elements in
the buffer is neither stable nor fully random. If random ordering is
desired, shuffle the result.</p>
<p>The length of the returned vector equals <code>amount</code> unless the iterator
contains insufficient elements, in which case it equals the number of
elements available.</p>
<p>Complexity is <code>O(n)</code> where <code>n</code> is the length of the iterator.
For slices, prefer <a href="trait.SliceRandom.html#tymethod.choose_multiple" title="method rand::seq::SliceRandom::choose_multiple"><code>SliceRandom::choose_multiple</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.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="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"><section id="impl-IteratorRandom-for-I" class="impl"><a class="src rightside" href="../../src/rand/seq/mod.rs.html#615">Source</a><a href="#impl-IteratorRandom-for-I" class="anchor">§</a><h3 class="code-header">impl&lt;I&gt; <a class="trait" href="trait.IteratorRandom.html" title="trait rand::seq::IteratorRandom">IteratorRandom</a> for I<div class="where">where
I: <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> + <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></h3></section></div><script src="../../trait.impl/rand/seq/trait.IteratorRandom.js" async></script></section></div></main></body></html>

View file

@ -0,0 +1,237 @@
<!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>

1
rand/sidebar-items.js Normal file
View file

@ -0,0 +1 @@
window.SIDEBAR_ITEMS = {"fn":["random","thread_rng"],"mod":["distributions","prelude","rngs","seq"],"struct":["Error"],"trait":["CryptoRng","Fill","Rng","RngCore","SeedableRng"]};

44
rand/struct.Error.html Normal file

File diff suppressed because one or more lines are too long

22
rand/trait.CryptoRng.html Normal file
View file

@ -0,0 +1,22 @@
<!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="A marker trait used to indicate that an `RngCore` or `BlockRngCore` implementation is supposed to be cryptographically secure."><title>CryptoRng in rand - 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="#">Crypto<wbr>Rng</a></h2><h3><a href="#foreign-impls">Implementations on Foreign Types</a></h3><ul class="block"><li><a href="#impl-CryptoRng-for-%26mut+R" title="&#38;&#39;a mut R">&#38;&#39;a mut R</a></li><li><a href="#impl-CryptoRng-for-Box%3CR%3E" title="Box&#60;R&#62;">Box&#60;R&#62;</a></li><li><a href="#impl-CryptoRng-for-ChaCha12Core" title="ChaCha12Core">ChaCha12Core</a></li><li><a href="#impl-CryptoRng-for-ChaCha12Rng" title="ChaCha12Rng">ChaCha12Rng</a></li><li><a href="#impl-CryptoRng-for-ChaCha20Core" title="ChaCha20Core">ChaCha20Core</a></li><li><a href="#impl-CryptoRng-for-ChaCha20Rng" title="ChaCha20Rng">ChaCha20Rng</a></li><li><a href="#impl-CryptoRng-for-ChaCha8Core" title="ChaCha8Core">ChaCha8Core</a></li><li><a href="#impl-CryptoRng-for-ChaCha8Rng" title="ChaCha8Rng">ChaCha8Rng</a></li></ul><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="index.html">In crate rand</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></span><h1>Trait <span class="trait">CryptoRng</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_core/lib.rs.html#209">Source</a> </span></div><pre class="rust item-decl"><code>pub trait CryptoRng { }</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>A marker trait used to indicate that an <a href="trait.RngCore.html" title="trait rand::RngCore"><code>RngCore</code></a> or <a href="../rand_core/block/trait.BlockRngCore.html" title="trait rand_core::block::BlockRngCore"><code>BlockRngCore</code></a>
implementation is supposed to be cryptographically secure.</p>
<p><em>Cryptographically secure generators</em>, also known as <em>CSPRNGs</em>, should
satisfy an additional properties over other generators: given the first
<em>k</em> bits of an algorithms output
sequence, it should not be possible using polynomial-time algorithms to
predict the next bit with probability significantly greater than 50%.</p>
<p>Some generators may satisfy an additional property, however this is not
required by this trait: if the CSPRNGs state is revealed, it should not be
computationally-feasible to reconstruct output prior to this. Some other
generators allow backwards-computation and are considered <em>reversible</em>.</p>
<p>Note that this trait is provided for guidance only and cannot guarantee
suitability for cryptographic applications. In general it should only be
implemented for well-reviewed code implementing well-regarded algorithms.</p>
<p>Note also that use of a <code>CryptoRng</code> does not protect against other
weaknesses such as seeding from a weak entropy source or leaking state.</p>
</div></details><h2 id="foreign-impls" class="section-header">Implementations on Foreign Types<a href="#foreign-impls" class="anchor">§</a></h2><section id="impl-CryptoRng-for-ChaCha8Core" class="impl"><a class="src rightside" href="../src/rand_chacha/chacha.rs.html#345">Source</a><a href="#impl-CryptoRng-for-ChaCha8Core" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.CryptoRng.html" title="trait rand::CryptoRng">CryptoRng</a> for <a class="struct" href="../rand_chacha/chacha/struct.ChaCha8Core.html" title="struct rand_chacha::chacha::ChaCha8Core">ChaCha8Core</a></h3></section><section id="impl-CryptoRng-for-ChaCha8Rng" class="impl"><a class="src rightside" href="../src/rand_chacha/chacha.rs.html#345">Source</a><a href="#impl-CryptoRng-for-ChaCha8Rng" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.CryptoRng.html" title="trait rand::CryptoRng">CryptoRng</a> for <a class="struct" href="../rand_chacha/chacha/struct.ChaCha8Rng.html" title="struct rand_chacha::chacha::ChaCha8Rng">ChaCha8Rng</a></h3></section><section id="impl-CryptoRng-for-ChaCha12Core" class="impl"><a class="src rightside" href="../src/rand_chacha/chacha.rs.html#344">Source</a><a href="#impl-CryptoRng-for-ChaCha12Core" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.CryptoRng.html" title="trait rand::CryptoRng">CryptoRng</a> for <a class="struct" href="../rand_chacha/chacha/struct.ChaCha12Core.html" title="struct rand_chacha::chacha::ChaCha12Core">ChaCha12Core</a></h3></section><section id="impl-CryptoRng-for-ChaCha12Rng" class="impl"><a class="src rightside" href="../src/rand_chacha/chacha.rs.html#344">Source</a><a href="#impl-CryptoRng-for-ChaCha12Rng" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.CryptoRng.html" title="trait rand::CryptoRng">CryptoRng</a> for <a class="struct" href="../rand_chacha/chacha/struct.ChaCha12Rng.html" title="struct rand_chacha::chacha::ChaCha12Rng">ChaCha12Rng</a></h3></section><section id="impl-CryptoRng-for-ChaCha20Core" class="impl"><a class="src rightside" href="../src/rand_chacha/chacha.rs.html#343">Source</a><a href="#impl-CryptoRng-for-ChaCha20Core" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.CryptoRng.html" title="trait rand::CryptoRng">CryptoRng</a> for <a class="struct" href="../rand_chacha/chacha/struct.ChaCha20Core.html" title="struct rand_chacha::chacha::ChaCha20Core">ChaCha20Core</a></h3></section><section id="impl-CryptoRng-for-ChaCha20Rng" class="impl"><a class="src rightside" href="../src/rand_chacha/chacha.rs.html#343">Source</a><a href="#impl-CryptoRng-for-ChaCha20Rng" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.CryptoRng.html" title="trait rand::CryptoRng">CryptoRng</a> for <a class="struct" href="../rand_chacha/chacha/struct.ChaCha20Rng.html" title="struct rand_chacha::chacha::ChaCha20Rng">ChaCha20Rng</a></h3></section><section id="impl-CryptoRng-for-%26mut+R" class="impl"><a class="src rightside" href="../src/rand_core/lib.rs.html#481">Source</a><a href="#impl-CryptoRng-for-%26mut+R" class="anchor">§</a><h3 class="code-header">impl&lt;'a, R&gt; <a class="trait" href="trait.CryptoRng.html" title="trait rand::CryptoRng">CryptoRng</a> for <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;'a mut R</a><div class="where">where
R: <a class="trait" href="trait.CryptoRng.html" title="trait rand::CryptoRng">CryptoRng</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></h3></section><section id="impl-CryptoRng-for-Box%3CR%3E" class="impl"><a class="src rightside" href="../src/rand_core/lib.rs.html#485">Source</a><a href="#impl-CryptoRng-for-Box%3CR%3E" class="anchor">§</a><h3 class="code-header">impl&lt;R&gt; <a class="trait" href="trait.CryptoRng.html" title="trait rand::CryptoRng">CryptoRng</a> for <a class="struct" href="https://doc.rust-lang.org/1.84.1/alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a>&lt;R&gt;<div class="where">where
R: <a class="trait" href="trait.CryptoRng.html" title="trait rand::CryptoRng">CryptoRng</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></h3></section><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"><section id="impl-CryptoRng-for-OsRng" class="impl"><a class="src rightside" href="../src/rand_core/os.rs.html#50">Source</a><a href="#impl-CryptoRng-for-OsRng" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.CryptoRng.html" title="trait rand::CryptoRng">CryptoRng</a> for <a class="struct" href="rngs/struct.OsRng.html" title="struct rand::rngs::OsRng">OsRng</a></h3></section><section id="impl-CryptoRng-for-StdRng" class="impl"><a class="src rightside" href="../src/rand/rngs/std.rs.html#72">Source</a><a href="#impl-CryptoRng-for-StdRng" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.CryptoRng.html" title="trait rand::CryptoRng">CryptoRng</a> for <a class="struct" href="rngs/struct.StdRng.html" title="struct rand::rngs::StdRng">StdRng</a></h3></section><section id="impl-CryptoRng-for-ThreadRng" class="impl"><a class="src rightside" href="../src/rand/rngs/thread.rs.html#131">Source</a><a href="#impl-CryptoRng-for-ThreadRng" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.CryptoRng.html" title="trait rand::CryptoRng">CryptoRng</a> for <a class="struct" href="rngs/struct.ThreadRng.html" title="struct rand::rngs::ThreadRng">ThreadRng</a></h3></section><section id="impl-CryptoRng-for-BlockRng%3CR%3E" class="impl"><a class="src rightside" href="../src/rand_core/block.rs.html#431">Source</a><a href="#impl-CryptoRng-for-BlockRng%3CR%3E" class="anchor">§</a><h3 class="code-header">impl&lt;R&gt; <a class="trait" href="trait.CryptoRng.html" title="trait rand::CryptoRng">CryptoRng</a> for <a class="struct" href="../rand_core/block/struct.BlockRng.html" title="struct rand_core::block::BlockRng">BlockRng</a>&lt;R&gt;<div class="where">where
R: <a class="trait" href="../rand_core/block/trait.BlockRngCore.html" title="trait rand_core::block::BlockRngCore">BlockRngCore</a> + <a class="trait" href="trait.CryptoRng.html" title="trait rand::CryptoRng">CryptoRng</a>,</div></h3></section><section id="impl-CryptoRng-for-ReseedingRng%3CR,+Rsdr%3E" class="impl"><a class="src rightside" href="../src/rand/rngs/adapter/reseeding.rs.html#149-154">Source</a><a href="#impl-CryptoRng-for-ReseedingRng%3CR,+Rsdr%3E" class="anchor">§</a><h3 class="code-header">impl&lt;R, Rsdr&gt; <a class="trait" href="trait.CryptoRng.html" title="trait rand::CryptoRng">CryptoRng</a> for <a class="struct" href="rngs/adapter/struct.ReseedingRng.html" title="struct rand::rngs::adapter::ReseedingRng">ReseedingRng</a>&lt;R, Rsdr&gt;<div class="where">where
R: <a class="trait" href="../rand_core/block/trait.BlockRngCore.html" title="trait rand_core::block::BlockRngCore">BlockRngCore</a> + <a class="trait" href="trait.SeedableRng.html" title="trait rand::SeedableRng">SeedableRng</a> + <a class="trait" href="trait.CryptoRng.html" title="trait rand::CryptoRng">CryptoRng</a>,
Rsdr: <a class="trait" href="trait.RngCore.html" title="trait rand::RngCore">RngCore</a> + <a class="trait" href="trait.CryptoRng.html" title="trait rand::CryptoRng">CryptoRng</a>,</div></h3></section></div><script src="../trait.impl/rand_core/trait.CryptoRng.js" data-ignore-extern-crates="rand_core,alloc,rand_chacha" async></script></section></div></main></body></html>

50
rand/trait.Fill.html Normal file

File diff suppressed because one or more lines are too long

180
rand/trait.Rng.html Normal file
View file

@ -0,0 +1,180 @@
<!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="An automatically-implemented extension trait on `RngCore` providing high-level generic methods for sampling values and other convenience methods."><title>Rng in rand - 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="#">Rng</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#generic-usage" title="Generic usage">Generic usage</a></li></ul><h3><a href="#provided-methods">Provided Methods</a></h3><ul class="block"><li><a href="#method.fill" title="fill">fill</a></li><li><a href="#method.gen" title="gen">gen</a></li><li><a href="#method.gen_bool" title="gen_bool">gen_bool</a></li><li><a href="#method.gen_range" title="gen_range">gen_range</a></li><li><a href="#method.gen_ratio" title="gen_ratio">gen_ratio</a></li><li><a href="#method.sample" title="sample">sample</a></li><li><a href="#method.sample_iter" title="sample_iter">sample_iter</a></li><li><a href="#method.try_fill" title="try_fill">try_fill</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 class="in-crate"><a href="index.html">In crate rand</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></span><h1>Trait <span class="trait">Rng</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/rng.rs.html#55-303">Source</a> </span></div><pre class="rust item-decl"><code>pub trait Rng: <a class="trait" href="trait.RngCore.html" title="trait rand::RngCore">RngCore</a> {
// Provided methods
fn <a href="#method.gen" class="fn">gen</a>&lt;T&gt;(&amp;mut self) -&gt; T
<span class="where">where <a class="struct" href="distributions/struct.Standard.html" title="struct rand::distributions::Standard">Standard</a>: <a class="trait" href="distributions/trait.Distribution.html" title="trait rand::distributions::Distribution">Distribution</a>&lt;T&gt;</span> { ... }
<span class="item-spacer"></span> fn <a href="#method.gen_range" class="fn">gen_range</a>&lt;T, R&gt;(&amp;mut self, range: R) -&gt; T
<span class="where">where T: <a class="trait" href="distributions/uniform/trait.SampleUniform.html" title="trait rand::distributions::uniform::SampleUniform">SampleUniform</a>,
R: <a class="trait" href="distributions/uniform/trait.SampleRange.html" title="trait rand::distributions::uniform::SampleRange">SampleRange</a>&lt;T&gt;</span> { ... }
<span class="item-spacer"></span> fn <a href="#method.sample" class="fn">sample</a>&lt;T, D: <a class="trait" href="distributions/trait.Distribution.html" title="trait rand::distributions::Distribution">Distribution</a>&lt;T&gt;&gt;(&amp;mut self, distr: D) -&gt; T { ... }
<span class="item-spacer"></span> fn <a href="#method.sample_iter" class="fn">sample_iter</a>&lt;T, D&gt;(self, distr: D) -&gt; <a class="struct" href="distributions/struct.DistIter.html" title="struct rand::distributions::DistIter">DistIter</a>&lt;D, Self, T&gt; <a href="#" class="tooltip" data-notable-ty="DistIter&lt;D, Self, T&gt;"></a>
<span class="where">where D: <a class="trait" href="distributions/trait.Distribution.html" title="trait rand::distributions::Distribution">Distribution</a>&lt;T&gt;,
Self: <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="#method.fill" class="fn">fill</a>&lt;T: <a class="trait" href="trait.Fill.html" title="trait rand::Fill">Fill</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>&gt;(&amp;mut self, dest: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;mut T</a>) { ... }
<span class="item-spacer"></span> fn <a href="#method.try_fill" class="fn">try_fill</a>&lt;T: <a class="trait" href="trait.Fill.html" title="trait rand::Fill">Fill</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>&gt;(&amp;mut self, dest: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;mut T</a>) -&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="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.unit.html">()</a>, <a class="struct" href="struct.Error.html" title="struct rand::Error">Error</a>&gt; { ... }
<span class="item-spacer"></span> fn <a href="#method.gen_bool" class="fn">gen_bool</a>(&amp;mut self, p: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.f64.html">f64</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.bool.html">bool</a> { ... }
<span class="item-spacer"></span> fn <a href="#method.gen_ratio" class="fn">gen_ratio</a>(&amp;mut self, numerator: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.u32.html">u32</a>, denominator: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.u32.html">u32</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.bool.html">bool</a> { ... }
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>An automatically-implemented extension trait on <a href="trait.RngCore.html" title="trait rand::RngCore"><code>RngCore</code></a> providing high-level
generic methods for sampling values and other convenience methods.</p>
<p>This is the primary trait to use when generating random values.</p>
<h2 id="generic-usage"><a class="doc-anchor" href="#generic-usage">§</a>Generic usage</h2>
<p>The basic pattern is <code>fn foo&lt;R: Rng + ?Sized&gt;(rng: &amp;mut R)</code>. Some
things are worth noting here:</p>
<ul>
<li>Since <code>Rng: RngCore</code> and every <code>RngCore</code> implements <code>Rng</code>, it makes no
difference whether we use <code>R: Rng</code> or <code>R: RngCore</code>.</li>
<li>The <code>+ ?Sized</code> un-bounding allows functions to be called directly on
type-erased references; i.e. <code>foo(r)</code> where <code>r: &amp;mut dyn RngCore</code>. Without
this it would be necessary to write <code>foo(&amp;mut r)</code>.</li>
</ul>
<p>An alternative pattern is possible: <code>fn foo&lt;R: Rng&gt;(rng: R)</code>. This has some
trade-offs. It allows the argument to be consumed directly without a <code>&amp;mut</code>
(which is how <code>from_rng(thread_rng())</code> works); also it still works directly
on references (including type-erased references). Unfortunately within the
function <code>foo</code> it is not known whether <code>rng</code> is a reference type or not,
hence many uses of <code>rng</code> require an extra reference, either explicitly
(<code>distr.sample(&amp;mut rng)</code>) or implicitly (<code>rng.gen()</code>); one may hope the
optimiser can remove redundant references later.</p>
<p>Example:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>rand::Rng;
<span class="kw">fn </span>foo&lt;R: Rng + <span class="question-mark">?</span>Sized&gt;(rng: <span class="kw-2">&amp;mut </span>R) -&gt; f32 {
rng.gen()
}
</code></pre></div>
</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.gen" class="method"><a class="src rightside" href="../src/rand/rng.rs.html#93-96">Source</a><h4 class="code-header">fn <a href="#method.gen" class="fn">gen</a>&lt;T&gt;(&amp;mut self) -&gt; T<div class="where">where
<a class="struct" href="distributions/struct.Standard.html" title="struct rand::distributions::Standard">Standard</a>: <a class="trait" href="distributions/trait.Distribution.html" title="trait rand::distributions::Distribution">Distribution</a>&lt;T&gt;,</div></h4></section></summary><div class="docblock"><p>Return a random value supporting the <a href="distributions/struct.Standard.html" title="struct rand::distributions::Standard"><code>Standard</code></a> distribution.</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, Rng};
<span class="kw">let </span><span class="kw-2">mut </span>rng = thread_rng();
<span class="kw">let </span>x: u32 = rng.gen();
<span class="macro">println!</span>(<span class="string">"{}"</span>, x);
<span class="macro">println!</span>(<span class="string">"{:?}"</span>, rng.gen::&lt;(f64, bool)&gt;());</code></pre></div>
<h5 id="arrays-and-tuples"><a class="doc-anchor" href="#arrays-and-tuples">§</a>Arrays and tuples</h5>
<p>The <code>rng.gen()</code> method is able to generate arrays (up to 32 elements)
and tuples (up to 12 elements), so long as all element types can be
generated.
When using <code>rustc</code> ≥ 1.51, enable the <code>min_const_gen</code> feature to support
arrays larger than 32 elements.</p>
<p>For arrays of integers, especially for those with small element types
(&lt; 64 bit), it will likely be faster to instead use <a href="trait.Rng.html#method.fill" title="method rand::Rng::fill"><code>Rng::fill</code></a>.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>rand::{thread_rng, Rng};
<span class="kw">let </span><span class="kw-2">mut </span>rng = thread_rng();
<span class="kw">let </span>tuple: (u8, i32, char) = rng.gen(); <span class="comment">// arbitrary tuple support
</span><span class="kw">let </span>arr1: [f32; <span class="number">32</span>] = rng.gen(); <span class="comment">// array construction
</span><span class="kw">let </span><span class="kw-2">mut </span>arr2 = [<span class="number">0u8</span>; <span class="number">128</span>];
rng.fill(<span class="kw-2">&amp;mut </span>arr2); <span class="comment">// array fill</span></code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.gen_range" class="method"><a class="src rightside" href="../src/rand/rng.rs.html#129-136">Source</a><h4 class="code-header">fn <a href="#method.gen_range" class="fn">gen_range</a>&lt;T, R&gt;(&amp;mut self, range: R) -&gt; T<div class="where">where
T: <a class="trait" href="distributions/uniform/trait.SampleUniform.html" title="trait rand::distributions::uniform::SampleUniform">SampleUniform</a>,
R: <a class="trait" href="distributions/uniform/trait.SampleRange.html" title="trait rand::distributions::uniform::SampleRange">SampleRange</a>&lt;T&gt;,</div></h4></section></summary><div class="docblock"><p>Generate a random value in the given range.</p>
<p>This function is optimised for the case that only a single sample is
made from the given range. See also the <a href="distributions/struct.Uniform.html" title="struct rand::distributions::Uniform"><code>Uniform</code></a> distribution
type which may be faster if sampling from the same range repeatedly.</p>
<p>Only <code>gen_range(low..high)</code> and <code>gen_range(low..=high)</code> are supported.</p>
<h5 id="panics"><a class="doc-anchor" href="#panics">§</a>Panics</h5>
<p>Panics if the range is empty.</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::{thread_rng, Rng};
<span class="kw">let </span><span class="kw-2">mut </span>rng = thread_rng();
<span class="comment">// Exclusive range
</span><span class="kw">let </span>n: u32 = rng.gen_range(<span class="number">0</span>..<span class="number">10</span>);
<span class="macro">println!</span>(<span class="string">"{}"</span>, n);
<span class="kw">let </span>m: f64 = rng.gen_range(-<span class="number">40.0</span>..<span class="number">1.3e5</span>);
<span class="macro">println!</span>(<span class="string">"{}"</span>, m);
<span class="comment">// Inclusive range
</span><span class="kw">let </span>n: u32 = rng.gen_range(<span class="number">0</span>..=<span class="number">10</span>);
<span class="macro">println!</span>(<span class="string">"{}"</span>, n);</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.sample" class="method"><a class="src rightside" href="../src/rand/rng.rs.html#152-154">Source</a><h4 class="code-header">fn <a href="#method.sample" class="fn">sample</a>&lt;T, D: <a class="trait" href="distributions/trait.Distribution.html" title="trait rand::distributions::Distribution">Distribution</a>&lt;T&gt;&gt;(&amp;mut self, distr: D) -&gt; T</h4></section></summary><div class="docblock"><p>Sample a new value, using the given distribution.</p>
<h6 id="example-2"><a class="doc-anchor" href="#example-2">§</a>Example</h6>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>rand::{thread_rng, Rng};
<span class="kw">use </span>rand::distributions::Uniform;
<span class="kw">let </span><span class="kw-2">mut </span>rng = thread_rng();
<span class="kw">let </span>x = rng.sample(Uniform::new(<span class="number">10u32</span>, <span class="number">15</span>));
<span class="comment">// Type annotation requires two types, the type and distribution; the
// distribution can be inferred.
</span><span class="kw">let </span>y = rng.sample::&lt;u16, <span class="kw">_</span>&gt;(Uniform::new(<span class="number">10</span>, <span class="number">15</span>));</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.sample_iter" class="method"><a class="src rightside" href="../src/rand/rng.rs.html#192-198">Source</a><h4 class="code-header">fn <a href="#method.sample_iter" class="fn">sample_iter</a>&lt;T, D&gt;(self, distr: D) -&gt; <a class="struct" href="distributions/struct.DistIter.html" title="struct rand::distributions::DistIter">DistIter</a>&lt;D, Self, T&gt; <a href="#" class="tooltip" data-notable-ty="DistIter&lt;D, Self, T&gt;"></a><div class="where">where
D: <a class="trait" href="distributions/trait.Distribution.html" title="trait rand::distributions::Distribution">Distribution</a>&lt;T&gt;,
Self: <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>Create an iterator that generates values using the given distribution.</p>
<p>Note that this function takes its arguments by value. This works since
<code>(&amp;mut R): Rng where R: Rng</code> and
<code>(&amp;D): Distribution where D: Distribution</code>,
however borrowing is not automatic hence <code>rng.sample_iter(...)</code> may
need to be replaced with <code>(&amp;mut rng).sample_iter(...)</code>.</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::{thread_rng, Rng};
<span class="kw">use </span>rand::distributions::{Alphanumeric, Uniform, Standard};
<span class="kw">let </span><span class="kw-2">mut </span>rng = thread_rng();
<span class="comment">// Vec of 16 x f32:
</span><span class="kw">let </span>v: Vec&lt;f32&gt; = (<span class="kw-2">&amp;mut </span>rng).sample_iter(Standard).take(<span class="number">16</span>).collect();
<span class="comment">// String:
</span><span class="kw">let </span>s: String = (<span class="kw-2">&amp;mut </span>rng).sample_iter(Alphanumeric)
.take(<span class="number">7</span>)
.map(char::from)
.collect();
<span class="comment">// Combined values
</span><span class="macro">println!</span>(<span class="string">"{:?}"</span>, (<span class="kw-2">&amp;mut </span>rng).sample_iter(Standard).take(<span class="number">5</span>)
.collect::&lt;Vec&lt;(f64, bool)&gt;&gt;());
<span class="comment">// Dice-rolling:
</span><span class="kw">let </span>die_range = Uniform::new_inclusive(<span class="number">1</span>, <span class="number">6</span>);
<span class="kw">let </span><span class="kw-2">mut </span>roll_die = (<span class="kw-2">&amp;mut </span>rng).sample_iter(die_range);
<span class="kw">while </span>roll_die.next().unwrap() != <span class="number">6 </span>{
<span class="macro">println!</span>(<span class="string">"Not a 6; rolling again!"</span>);
}</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.fill" class="method"><a class="src rightside" href="../src/rand/rng.rs.html#218-220">Source</a><h4 class="code-header">fn <a href="#method.fill" class="fn">fill</a>&lt;T: <a class="trait" href="trait.Fill.html" title="trait rand::Fill">Fill</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>&gt;(&amp;mut self, dest: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;mut T</a>)</h4></section></summary><div class="docblock"><p>Fill any type implementing <a href="trait.Fill.html" title="trait rand::Fill"><code>Fill</code></a> with random data</p>
<p>The distribution is expected to be uniform with portable results, but
this cannot be guaranteed for third-party implementations.</p>
<p>This is identical to <a href="trait.Rng.html#method.try_fill" title="method rand::Rng::try_fill"><code>try_fill</code></a> except that it panics on error.</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::{thread_rng, Rng};
<span class="kw">let </span><span class="kw-2">mut </span>arr = [<span class="number">0i8</span>; <span class="number">20</span>];
thread_rng().fill(<span class="kw-2">&amp;mut </span>arr[..]);</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.try_fill" class="method"><a class="src rightside" href="../src/rand/rng.rs.html#246-248">Source</a><h4 class="code-header">fn <a href="#method.try_fill" class="fn">try_fill</a>&lt;T: <a class="trait" href="trait.Fill.html" title="trait rand::Fill">Fill</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>&gt;(&amp;mut self, dest: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;mut T</a>) -&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="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.unit.html">()</a>, <a class="struct" href="struct.Error.html" title="struct rand::Error">Error</a>&gt;</h4></section></summary><div class="docblock"><p>Fill any type implementing <a href="trait.Rng.html#method.fill" title="method rand::Rng::fill"><code>Fill</code></a> with random data</p>
<p>The distribution is expected to be uniform with portable results, but
this cannot be guaranteed for third-party implementations.</p>
<p>This is identical to <a href="trait.Rng.html#method.fill" title="method rand::Rng::fill"><code>fill</code></a> except that it forwards errors.</p>
<h5 id="example-5"><a class="doc-anchor" href="#example-5">§</a>Example</h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>rand::{thread_rng, Rng};
<span class="kw">let </span><span class="kw-2">mut </span>arr = [<span class="number">0u64</span>; <span class="number">4</span>];
thread_rng().try_fill(<span class="kw-2">&amp;mut </span>arr[..])<span class="question-mark">?</span>;
</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.gen_bool" class="method"><a class="src rightside" href="../src/rand/rng.rs.html#270-273">Source</a><h4 class="code-header">fn <a href="#method.gen_bool" class="fn">gen_bool</a>(&amp;mut self, p: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.f64.html">f64</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.bool.html">bool</a></h4></section></summary><div class="docblock"><p>Return a bool with a probability <code>p</code> of being true.</p>
<p>See also the <a href="distributions/struct.Bernoulli.html" title="struct rand::distributions::Bernoulli"><code>Bernoulli</code></a> distribution, which may be faster if
sampling from the same probability repeatedly.</p>
<h5 id="example-6"><a class="doc-anchor" href="#example-6">§</a>Example</h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>rand::{thread_rng, Rng};
<span class="kw">let </span><span class="kw-2">mut </span>rng = thread_rng();
<span class="macro">println!</span>(<span class="string">"{}"</span>, rng.gen_bool(<span class="number">1.0 </span>/ <span class="number">3.0</span>));</code></pre></div>
<h5 id="panics-1"><a class="doc-anchor" href="#panics-1">§</a>Panics</h5>
<p>If <code>p &lt; 0</code> or <code>p &gt; 1</code>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.gen_ratio" class="method"><a class="src rightside" href="../src/rand/rng.rs.html#299-302">Source</a><h4 class="code-header">fn <a href="#method.gen_ratio" class="fn">gen_ratio</a>(&amp;mut self, numerator: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.u32.html">u32</a>, denominator: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.u32.html">u32</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.bool.html">bool</a></h4></section></summary><div class="docblock"><p>Return a bool with a probability of <code>numerator/denominator</code> of being
true. I.e. <code>gen_ratio(2, 3)</code> has chance of 2 in 3, or about 67%, of
returning true. If <code>numerator == denominator</code>, then the returned value
is guaranteed to be <code>true</code>. If <code>numerator == 0</code>, then the returned
value is guaranteed to be <code>false</code>.</p>
<p>See also the <a href="distributions/struct.Bernoulli.html" title="struct rand::distributions::Bernoulli"><code>Bernoulli</code></a> distribution, which may be faster if
sampling from the same <code>numerator</code> and <code>denominator</code> repeatedly.</p>
<h5 id="panics-2"><a class="doc-anchor" href="#panics-2">§</a>Panics</h5>
<p>If <code>denominator == 0</code> or <code>numerator &gt; denominator</code>.</p>
<h5 id="example-7"><a class="doc-anchor" href="#example-7">§</a>Example</h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>rand::{thread_rng, Rng};
<span class="kw">let </span><span class="kw-2">mut </span>rng = thread_rng();
<span class="macro">println!</span>(<span class="string">"{}"</span>, rng.gen_ratio(<span class="number">2</span>, <span class="number">3</span>));</code></pre></div>
</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="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"><section id="impl-Rng-for-R" class="impl"><a class="src rightside" href="../src/rand/rng.rs.html#305">Source</a><a href="#impl-Rng-for-R" class="anchor">§</a><h3 class="code-header">impl&lt;R: <a class="trait" href="trait.RngCore.html" title="trait rand::RngCore">RngCore</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>&gt; <a class="trait" href="trait.Rng.html" title="trait rand::Rng">Rng</a> for R</h3></section></div><script src="../trait.impl/rand/rng/trait.Rng.js" async></script><script type="text/json" id="notable-traits-data">{"DistIter<D, Self, T>":"<h3>Notable traits for <code><a class=\"struct\" href=\"distributions/struct.DistIter.html\" title=\"struct rand::distributions::DistIter\">DistIter</a>&lt;D, R, T&gt;</code></h3><pre><code><div class=\"where\">impl&lt;D, R, T&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=\"distributions/struct.DistIter.html\" title=\"struct rand::distributions::DistIter\">DistIter</a>&lt;D, R, T&gt;<div class=\"where\">where\n D: <a class=\"trait\" href=\"distributions/trait.Distribution.html\" title=\"trait rand::distributions::Distribution\">Distribution</a>&lt;T&gt;,\n R: <a class=\"trait\" href=\"trait.Rng.html\" title=\"trait rand::Rng\">Rng</a>,</div></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> = T;</div>"}</script></section></div></main></body></html>

113
rand/trait.RngCore.html Normal file

File diff suppressed because one or more lines are too long

114
rand/trait.SeedableRng.html Normal file

File diff suppressed because one or more lines are too long