354 lines
No EOL
66 KiB
HTML
354 lines
No EOL
66 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<meta name="generator" content="rustdoc">
|
||
<meta name="description" content="API documentation for the Rust `Rng` trait in crate `rand`.">
|
||
<meta name="keywords" content="rust, rustlang, rust-lang, Rng">
|
||
|
||
<title>rand::Rng - Rust</title>
|
||
|
||
<link rel="stylesheet" type="text/css" href="../normalize.css">
|
||
<link rel="stylesheet" type="text/css" href="../rustdoc.css" id="mainThemeStyle">
|
||
|
||
<link rel="stylesheet" type="text/css" href="../dark.css">
|
||
<link rel="stylesheet" type="text/css" href="../main.css" id="themeStyle">
|
||
<script src="../storage.js"></script>
|
||
|
||
|
||
<link rel="shortcut icon" href="https://www.rust-lang.org/favicon.ico">
|
||
|
||
</head>
|
||
<body class="rustdoc trait">
|
||
<!--[if lte IE 8]>
|
||
<div class="warning">
|
||
This old browser is unsupported and will most likely display funky
|
||
things.
|
||
</div>
|
||
<![endif]-->
|
||
|
||
|
||
|
||
<nav class="sidebar">
|
||
<div class="sidebar-menu">☰</div>
|
||
<a href='../rand/index.html'><img src='https://www.rust-lang.org/logos/rust-logo-128x128-blk.png' alt='logo' width='100'></a>
|
||
<p class='location'>Trait Rng</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#required-methods">Required Methods</a><div class="sidebar-links"><a href="#tymethod.next_u32">next_u32</a></div><a class="sidebar-title" href="#provided-methods">Provided Methods</a><div class="sidebar-links"><a href="#method.next_u64">next_u64</a><a href="#method.next_f32">next_f32</a><a href="#method.next_f64">next_f64</a><a href="#method.fill_bytes">fill_bytes</a><a href="#method.gen">gen</a><a href="#method.gen_iter">gen_iter</a><a href="#method.gen_range">gen_range</a><a href="#method.gen_weighted_bool">gen_weighted_bool</a><a href="#method.gen_ascii_chars">gen_ascii_chars</a><a href="#method.choose">choose</a><a href="#method.choose_mut">choose_mut</a><a href="#method.shuffle">shuffle</a></div><a class="sidebar-title" href="#foreign-impls">Implementations on Foreign Types</a><div class="sidebar-links"><a href="#impl-Rng">&'a mut R</a><a href="#impl-Rng">JitterRng</a><a href="#impl-Rng">Box<R></a></div><a class="sidebar-title" href="#implementors">Implementors</a></div><p class='location'><a href='index.html'>rand</a></p><script>window.sidebarCurrent = {name: 'Rng', ty: 'trait', relpath: ''};</script><script defer src="sidebar-items.js"></script></div>
|
||
</nav>
|
||
|
||
<div class="theme-picker">
|
||
<button id="theme-picker" aria-label="Pick another theme!">
|
||
<img src="../brush.svg" width="18" alt="Pick another theme!">
|
||
</button>
|
||
<div id="theme-choices"></div>
|
||
</div>
|
||
<script src="../theme.js"></script>
|
||
<nav class="sub">
|
||
<form class="search-form js-only">
|
||
<div class="search-container">
|
||
<input class="search-input" name="search"
|
||
autocomplete="off"
|
||
placeholder="Click or press ‘S’ to search, ‘?’ for more options…"
|
||
type="search">
|
||
</div>
|
||
</form>
|
||
</nav>
|
||
|
||
<section id='main' class="content">
|
||
<h1 class='fqn'><span class='in-band'>Trait <a href='index.html'>rand</a>::<wbr><a class="trait" href=''>Rng</a></span><span class='out-of-band'><span id='render-detail'>
|
||
<a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">
|
||
[<span class='inner'>−</span>]
|
||
</a>
|
||
</span><a class='srclink' href='../src/rand/lib.rs.html#339-611' title='goto source code'>[src]</a></span></h1>
|
||
<pre class='rust trait'>pub trait Rng {
|
||
fn <a href='#tymethod.next_u32' class='fnname'>next_u32</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>;
|
||
|
||
fn <a href='#method.next_u64' class='fnname'>next_u64</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u64.html">u64</a> { ... }
|
||
<div class='item-spacer'></div> fn <a href='#method.next_f32' class='fnname'>next_f32</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.f32.html">f32</a> { ... }
|
||
<div class='item-spacer'></div> fn <a href='#method.next_f64' class='fnname'>next_f64</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.f64.html">f64</a> { ... }
|
||
<div class='item-spacer'></div> fn <a href='#method.fill_bytes' class='fnname'>fill_bytes</a>(&mut self, dest: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&mut [</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>) { ... }
|
||
<div class='item-spacer'></div> fn <a href='#method.gen' class='fnname'>gen</a><T>(&mut self) -> T<br> <span class="where">where<br> T: <a class="trait" href="../rand/trait.Rand.html" title="trait rand::Rand">Rand</a></span>,
|
||
{ ... }
|
||
<div class='item-spacer'></div> fn <a href='#method.gen_iter' class='fnname'>gen_iter</a><T>(&'a mut self) -> <a class="struct" href="../rand/struct.Generator.html" title="struct rand::Generator">Generator</a><'a, T, Self><br> <span class="where">where<br> T: <a class="trait" href="../rand/trait.Rand.html" title="trait rand::Rand">Rand</a></span>,
|
||
{ ... }
|
||
<div class='item-spacer'></div> fn <a href='#method.gen_range' class='fnname'>gen_range</a><T>(&mut self, low: T, high: T) -> T<br> <span class="where">where<br> T: <a class="trait" href="../rand/distributions/range/trait.SampleRange.html" title="trait rand::distributions::range::SampleRange">SampleRange</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a><T></span>,
|
||
{ ... }
|
||
<div class='item-spacer'></div> fn <a href='#method.gen_weighted_bool' class='fnname'>gen_weighted_bool</a>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a> { ... }
|
||
<div class='item-spacer'></div> fn <a href='#method.gen_ascii_chars' class='fnname'>gen_ascii_chars</a>(&'a mut self) -> <a class="struct" href="../rand/struct.AsciiGenerator.html" title="struct rand::AsciiGenerator">AsciiGenerator</a><'a, Self> { ... }
|
||
<div class='item-spacer'></div> fn <a href='#method.choose' class='fnname'>choose</a><T>(&mut self, values: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&'a [T]</a>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a </a>T> { ... }
|
||
<div class='item-spacer'></div> fn <a href='#method.choose_mut' class='fnname'>choose_mut</a><T>(&mut self, values: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&'a mut [T]</a>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>T> { ... }
|
||
<div class='item-spacer'></div> fn <a href='#method.shuffle' class='fnname'>shuffle</a><T>(&mut self, values: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&mut [T]</a>) { ... }
|
||
}</pre><div class='docblock'><p>A random number generator.</p>
|
||
</div>
|
||
<h2 id='required-methods' class='small-section-header'>
|
||
Required Methods<a href='#required-methods' class='anchor'></a>
|
||
</h2>
|
||
<div class='methods'>
|
||
<h3 id='tymethod.next_u32' class='method'><span id='next_u32.v' class='invisible'><code>fn <a href='#tymethod.next_u32' class='fnname'>next_u32</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a></code></span></h3><div class='docblock'><p>Return the next random u32.</p>
|
||
<p>This rarely needs to be called directly, prefer <code>r.gen()</code> to
|
||
<code>r.next_u32()</code>.</p>
|
||
</div></div>
|
||
<h2 id='provided-methods' class='small-section-header'>
|
||
Provided Methods<a href='#provided-methods' class='anchor'></a>
|
||
</h2>
|
||
<div class='methods'>
|
||
<h3 id='method.next_u64' class='method'><span id='next_u64.v' class='invisible'><code>fn <a href='#method.next_u64' class='fnname'>next_u64</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u64.html">u64</a></code></span></h3><div class='docblock'><p>Return the next random u64.</p>
|
||
<p>By default this is implemented in terms of <code>next_u32</code>. An
|
||
implementation of this trait must provide at least one of
|
||
these two methods. Similarly to <code>next_u32</code>, this rarely needs
|
||
to be called directly, prefer <code>r.gen()</code> to <code>r.next_u64()</code>.</p>
|
||
</div><h3 id='method.next_f32' class='method'><span id='next_f32.v' class='invisible'><code>fn <a href='#method.next_f32' class='fnname'>next_f32</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.f32.html">f32</a></code></span></h3><div class='docblock'><p>Return the next random f32 selected from the half-open
|
||
interval <code>[0, 1)</code>.</p>
|
||
<p>This uses a technique described by Saito and Matsumoto at
|
||
MCQMC'08. Given that the IEEE floating point numbers are
|
||
uniformly distributed over [1,2), we generate a number in
|
||
this range and then offset it onto the range [0,1). Our
|
||
choice of bits (masking v. shifting) is arbitrary and
|
||
should be immaterial for high quality generators. For low
|
||
quality generators (ex. LCG), prefer bitshifting due to
|
||
correlation between sequential low order bits.</p>
|
||
<p>See:
|
||
A PRNG specialized in double precision floating point numbers using
|
||
an affine transition</p>
|
||
<ul>
|
||
<li><a href="http://www.math.sci.hiroshima-u.ac.jp/%7Em-mat/MT/ARTICLES/dSFMT.pdf">http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/ARTICLES/dSFMT.pdf</a></li>
|
||
<li><a href="http://www.math.sci.hiroshima-u.ac.jp/%7Em-mat/MT/SFMT/dSFMT-slide-e.pdf">http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/dSFMT-slide-e.pdf</a></li>
|
||
</ul>
|
||
<p>By default this is implemented in terms of <code>next_u32</code>, but a
|
||
random number generator which can generate numbers satisfying
|
||
the requirements directly can overload this for performance.
|
||
It is required that the return value lies in <code>[0, 1)</code>.</p>
|
||
<p>See <code>Closed01</code> for the closed interval <code>[0,1]</code>, and
|
||
<code>Open01</code> for the open interval <code>(0,1)</code>.</p>
|
||
</div><h3 id='method.next_f64' class='method'><span id='next_f64.v' class='invisible'><code>fn <a href='#method.next_f64' class='fnname'>next_f64</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.f64.html">f64</a></code></span></h3><div class='docblock'><p>Return the next random f64 selected from the half-open
|
||
interval <code>[0, 1)</code>.</p>
|
||
<p>By default this is implemented in terms of <code>next_u64</code>, but a
|
||
random number generator which can generate numbers satisfying
|
||
the requirements directly can overload this for performance.
|
||
It is required that the return value lies in <code>[0, 1)</code>.</p>
|
||
<p>See <code>Closed01</code> for the closed interval <code>[0,1]</code>, and
|
||
<code>Open01</code> for the open interval <code>(0,1)</code>.</p>
|
||
</div><h3 id='method.fill_bytes' class='method'><span id='fill_bytes.v' class='invisible'><code>fn <a href='#method.fill_bytes' class='fnname'>fill_bytes</a>(&mut self, dest: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&mut [</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>)</code></span></h3><div class='docblock'><p>Fill <code>dest</code> with random data.</p>
|
||
<p>This has a default implementation in terms of <code>next_u64</code> and
|
||
<code>next_u32</code>, but should be overridden by implementations that
|
||
offer a more efficient solution than just calling those
|
||
methods repeatedly.</p>
|
||
<p>This method does <em>not</em> have a requirement to bear any fixed
|
||
relationship to the other methods, for example, it does <em>not</em>
|
||
have to result in the same output as progressively filling
|
||
<code>dest</code> with <code>self.gen::<u8>()</code>, and any such behaviour should
|
||
not be relied upon.</p>
|
||
<p>This method should guarantee that <code>dest</code> is entirely filled
|
||
with new data, and may panic if this is impossible
|
||
(e.g. reading past the end of a file that is being used as the
|
||
source of randomness).</p>
|
||
<h1 id="example" class="section-header"><a href="#example">Example</a></h1>
|
||
<pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">rand</span>::{<span class="ident">thread_rng</span>, <span class="ident">Rng</span>};
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">v</span> <span class="op">=</span> [<span class="number">0u8</span>; <span class="number">13579</span>];
|
||
<span class="ident">thread_rng</span>().<span class="ident">fill_bytes</span>(<span class="kw-2">&</span><span class="kw-2">mut</span> <span class="ident">v</span>);
|
||
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"{:?}"</span>, <span class="kw-2">&</span><span class="ident">v</span>[..]);</pre>
|
||
</div><h3 id='method.gen' class='method'><span id='gen.v' class='invisible'><code>fn <a href='#method.gen' class='fnname'>gen</a><T>(&mut self) -> T <span class="where fmt-newline">where<br> T: <a class="trait" href="../rand/trait.Rand.html" title="trait rand::Rand">Rand</a>, </span></code></span></h3><div class='docblock'><p>Return a random value of a <code>Rand</code> type.</p>
|
||
<h1 id="example-1" class="section-header"><a href="#example-1">Example</a></h1>
|
||
<pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">rand</span>::{<span class="ident">thread_rng</span>, <span class="ident">Rng</span>};
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">rng</span> <span class="op">=</span> <span class="ident">thread_rng</span>();
|
||
<span class="kw">let</span> <span class="ident">x</span>: <span class="ident">u32</span> <span class="op">=</span> <span class="ident">rng</span>.<span class="ident">gen</span>();
|
||
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"{}"</span>, <span class="ident">x</span>);
|
||
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"{:?}"</span>, <span class="ident">rng</span>.<span class="ident">gen</span>::<span class="op"><</span>(<span class="ident">f64</span>, <span class="ident">bool</span>)<span class="op">></span>());</pre>
|
||
</div><div class="important-traits"><div class='tooltip'>ⓘ<span class='tooltiptext'>Important traits for <a class="struct" href="../rand/struct.Generator.html" title="struct rand::Generator">Generator</a><'a, T, R></span></div><div class="content hidden"><h3 class="important">Important traits for <a class="struct" href="../rand/struct.Generator.html" title="struct rand::Generator">Generator</a><'a, T, R></h3><code class="content"><span class="where fmt-newline">impl<'a, T, R> <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/iterator/trait.Iterator.html" title="trait core::iter::iterator::Iterator">Iterator</a> for <a class="struct" href="../rand/struct.Generator.html" title="struct rand::Generator">Generator</a><'a, T, R> <span class="where fmt-newline">where<br> R: <a class="trait" href="../rand/trait.Rng.html" title="trait rand::Rng">Rng</a>,<br> T: <a class="trait" href="../rand/trait.Rand.html" title="trait rand::Rand">Rand</a>, </span></span><span class="where fmt-newline"> type <a href='https://doc.rust-lang.org/nightly/core/iter/iterator/trait.Iterator.html#associatedtype.Item' class="type">Item</a> = T;</span></code></div></div><h3 id='method.gen_iter' class='method'><span id='gen_iter.v' class='invisible'><code>fn <a href='#method.gen_iter' class='fnname'>gen_iter</a><T>(&'a mut self) -> <a class="struct" href="../rand/struct.Generator.html" title="struct rand::Generator">Generator</a><'a, T, Self> <span class="where fmt-newline">where<br> T: <a class="trait" href="../rand/trait.Rand.html" title="trait rand::Rand">Rand</a>, </span></code></span></h3><div class='docblock'><p>Return an iterator that will yield an infinite number of randomly
|
||
generated items.</p>
|
||
<h1 id="example-2" class="section-header"><a href="#example-2">Example</a></h1>
|
||
<pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">rand</span>::{<span class="ident">thread_rng</span>, <span class="ident">Rng</span>};
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">rng</span> <span class="op">=</span> <span class="ident">thread_rng</span>();
|
||
<span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="ident">rng</span>.<span class="ident">gen_iter</span>::<span class="op"><</span><span class="ident">u32</span><span class="op">></span>().<span class="ident">take</span>(<span class="number">10</span>).<span class="ident">collect</span>::<span class="op"><</span><span class="ident">Vec</span><span class="op"><</span><span class="ident">u32</span><span class="op">>></span>();
|
||
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"{:?}"</span>, <span class="ident">x</span>);
|
||
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"{:?}"</span>, <span class="ident">rng</span>.<span class="ident">gen_iter</span>::<span class="op"><</span>(<span class="ident">f64</span>, <span class="ident">bool</span>)<span class="op">></span>().<span class="ident">take</span>(<span class="number">5</span>)
|
||
.<span class="ident">collect</span>::<span class="op"><</span><span class="ident">Vec</span><span class="op"><</span>(<span class="ident">f64</span>, <span class="ident">bool</span>)<span class="op">>></span>());</pre>
|
||
</div><h3 id='method.gen_range' class='method'><span id='gen_range.v' class='invisible'><code>fn <a href='#method.gen_range' class='fnname'>gen_range</a><T>(&mut self, low: T, high: T) -> T <span class="where fmt-newline">where<br> T: <a class="trait" href="../rand/distributions/range/trait.SampleRange.html" title="trait rand::distributions::range::SampleRange">SampleRange</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a><T>, </span></code></span></h3><div class='docblock'><p>Generate a random value in the range [<code>low</code>, <code>high</code>).</p>
|
||
<p>This is a convenience wrapper around
|
||
<code>distributions::Range</code>. If this function will be called
|
||
repeatedly with the same arguments, one should use <code>Range</code>, as
|
||
that will amortize the computations that allow for perfect
|
||
uniformity, as they only happen on initialization.</p>
|
||
<h1 id="panics" class="section-header"><a href="#panics">Panics</a></h1>
|
||
<p>Panics if <code>low >= high</code>.</p>
|
||
<h1 id="example-3" class="section-header"><a href="#example-3">Example</a></h1>
|
||
<pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">rand</span>::{<span class="ident">thread_rng</span>, <span class="ident">Rng</span>};
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">rng</span> <span class="op">=</span> <span class="ident">thread_rng</span>();
|
||
<span class="kw">let</span> <span class="ident">n</span>: <span class="ident">u32</span> <span class="op">=</span> <span class="ident">rng</span>.<span class="ident">gen_range</span>(<span class="number">0</span>, <span class="number">10</span>);
|
||
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"{}"</span>, <span class="ident">n</span>);
|
||
<span class="kw">let</span> <span class="ident">m</span>: <span class="ident">f64</span> <span class="op">=</span> <span class="ident">rng</span>.<span class="ident">gen_range</span>(<span class="op">-</span><span class="number">40.0f64</span>, <span class="number">1.3e5f64</span>);
|
||
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"{}"</span>, <span class="ident">m</span>);</pre>
|
||
</div><h3 id='method.gen_weighted_bool' class='method'><span id='gen_weighted_bool.v' class='invisible'><code>fn <a href='#method.gen_weighted_bool' class='fnname'>gen_weighted_bool</a>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code></span></h3><div class='docblock'><p>Return a bool with a 1 in n chance of true</p>
|
||
<h1 id="example-4" class="section-header"><a href="#example-4">Example</a></h1>
|
||
<pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">rand</span>::{<span class="ident">thread_rng</span>, <span class="ident">Rng</span>};
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">rng</span> <span class="op">=</span> <span class="ident">thread_rng</span>();
|
||
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"{}"</span>, <span class="ident">rng</span>.<span class="ident">gen_weighted_bool</span>(<span class="number">3</span>));</pre>
|
||
</div><div class="important-traits"><div class='tooltip'>ⓘ<span class='tooltiptext'>Important traits for <a class="struct" href="../rand/struct.AsciiGenerator.html" title="struct rand::AsciiGenerator">AsciiGenerator</a><'a, R></span></div><div class="content hidden"><h3 class="important">Important traits for <a class="struct" href="../rand/struct.AsciiGenerator.html" title="struct rand::AsciiGenerator">AsciiGenerator</a><'a, R></h3><code class="content"><span class="where fmt-newline">impl<'a, R> <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/iterator/trait.Iterator.html" title="trait core::iter::iterator::Iterator">Iterator</a> for <a class="struct" href="../rand/struct.AsciiGenerator.html" title="struct rand::AsciiGenerator">AsciiGenerator</a><'a, R> <span class="where fmt-newline">where<br> R: <a class="trait" href="../rand/trait.Rng.html" title="trait rand::Rng">Rng</a>, </span></span><span class="where fmt-newline"> type <a href='https://doc.rust-lang.org/nightly/core/iter/iterator/trait.Iterator.html#associatedtype.Item' class="type">Item</a> = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.char.html">char</a>;</span></code></div></div><h3 id='method.gen_ascii_chars' class='method'><span id='gen_ascii_chars.v' class='invisible'><code>fn <a href='#method.gen_ascii_chars' class='fnname'>gen_ascii_chars</a>(&'a mut self) -> <a class="struct" href="../rand/struct.AsciiGenerator.html" title="struct rand::AsciiGenerator">AsciiGenerator</a><'a, Self></code></span></h3><div class='docblock'><p>Return an iterator of random characters from the set A-Z,a-z,0-9.</p>
|
||
<h1 id="example-5" class="section-header"><a href="#example-5">Example</a></h1>
|
||
<pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">rand</span>::{<span class="ident">thread_rng</span>, <span class="ident">Rng</span>};
|
||
|
||
<span class="kw">let</span> <span class="ident">s</span>: <span class="ident">String</span> <span class="op">=</span> <span class="ident">thread_rng</span>().<span class="ident">gen_ascii_chars</span>().<span class="ident">take</span>(<span class="number">10</span>).<span class="ident">collect</span>();
|
||
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"{}"</span>, <span class="ident">s</span>);</pre>
|
||
</div><h3 id='method.choose' class='method'><span id='choose.v' class='invisible'><code>fn <a href='#method.choose' class='fnname'>choose</a><T>(&mut self, values: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&'a [T]</a>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a </a>T></code></span></h3><div class='docblock'><p>Return a random element from <code>values</code>.</p>
|
||
<p>Return <code>None</code> if <code>values</code> is empty.</p>
|
||
<h1 id="example-6" class="section-header"><a href="#example-6">Example</a></h1>
|
||
<pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">rand</span>::{<span class="ident">thread_rng</span>, <span class="ident">Rng</span>};
|
||
|
||
<span class="kw">let</span> <span class="ident">choices</span> <span class="op">=</span> [<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> <span class="ident">rng</span> <span class="op">=</span> <span class="ident">thread_rng</span>();
|
||
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"{:?}"</span>, <span class="ident">rng</span>.<span class="ident">choose</span>(<span class="kw-2">&</span><span class="ident">choices</span>));
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">rng</span>.<span class="ident">choose</span>(<span class="kw-2">&</span><span class="ident">choices</span>[..<span class="number">0</span>]), <span class="prelude-val">None</span>);</pre>
|
||
</div><h3 id='method.choose_mut' class='method'><span id='choose_mut.v' class='invisible'><code>fn <a href='#method.choose_mut' class='fnname'>choose_mut</a><T>(&mut self, values: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&'a mut [T]</a>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>T></code></span></h3><div class='docblock'><p>Return a mutable pointer to a random element from <code>values</code>.</p>
|
||
<p>Return <code>None</code> if <code>values</code> is empty.</p>
|
||
</div><h3 id='method.shuffle' class='method'><span id='shuffle.v' class='invisible'><code>fn <a href='#method.shuffle' class='fnname'>shuffle</a><T>(&mut self, values: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&mut [T]</a>)</code></span></h3><div class='docblock'><p>Shuffle a mutable slice in place.</p>
|
||
<p>This applies Durstenfeld's algorithm for the <a href="https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#The_modern_algorithm">Fisher–Yates shuffle</a>
|
||
which produces an unbiased permutation.</p>
|
||
<h1 id="example-7" class="section-header"><a href="#example-7">Example</a></h1>
|
||
<pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">rand</span>::{<span class="ident">thread_rng</span>, <span class="ident">Rng</span>};
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">rng</span> <span class="op">=</span> <span class="ident">thread_rng</span>();
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">y</span> <span class="op">=</span> [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>];
|
||
<span class="ident">rng</span>.<span class="ident">shuffle</span>(<span class="kw-2">&</span><span class="kw-2">mut</span> <span class="ident">y</span>);
|
||
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"{:?}"</span>, <span class="ident">y</span>);
|
||
<span class="ident">rng</span>.<span class="ident">shuffle</span>(<span class="kw-2">&</span><span class="kw-2">mut</span> <span class="ident">y</span>);
|
||
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"{:?}"</span>, <span class="ident">y</span>);</pre>
|
||
</div></div>
|
||
<h2 id='foreign-impls' class='small-section-header'>
|
||
Implementations on Foreign Types<a href='#foreign-impls' class='anchor'></a>
|
||
</h2>
|
||
<h3 id='impl-Rng' class='impl'><span class='in-band'><code>impl<'a, R> <a class="trait" href="../rand/trait.Rng.html" title="trait rand::Rng">Rng</a> for <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>R <span class="where fmt-newline">where<br> R: <a class="trait" href="../rand/trait.Rng.html" title="trait rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></code><a href='#impl-Rng' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/rand/lib.rs.html#613-633' title='goto source code'>[src]</a></span></h3>
|
||
<span class='docblock autohide'><div class='impl-items'><h4 id='method.next_u32' class="method"><span id='next_u32.v-1' class='invisible'><code>fn <a href='#method.next_u32' class='fnname'>next_u32</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/rand/lib.rs.html#614-616' title='goto source code'>[src]</a></span></h4>
|
||
<h4 id='method.next_u64-1' class="method"><span id='next_u64.v-1' class='invisible'><code>fn <a href='#method.next_u64' class='fnname'>next_u64</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u64.html">u64</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/rand/lib.rs.html#618-620' title='goto source code'>[src]</a></span></h4>
|
||
<h4 id='method.next_f32-1' class="method"><span id='next_f32.v-1' class='invisible'><code>fn <a href='#method.next_f32' class='fnname'>next_f32</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.f32.html">f32</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/rand/lib.rs.html#622-624' title='goto source code'>[src]</a></span></h4>
|
||
<h4 id='method.next_f64-1' class="method"><span id='next_f64.v-1' class='invisible'><code>fn <a href='#method.next_f64' class='fnname'>next_f64</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.f64.html">f64</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/rand/lib.rs.html#626-628' title='goto source code'>[src]</a></span></h4>
|
||
<h4 id='method.fill_bytes-1' class="method"><span id='fill_bytes.v-1' class='invisible'><code>fn <a href='#method.fill_bytes' class='fnname'>fill_bytes</a>(&mut self, dest: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&mut [</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>)</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/rand/lib.rs.html#630-632' title='goto source code'>[src]</a></span></h4>
|
||
<h4 id='method.gen-1' class="method"><span id='gen.v-1' class='invisible'><code>fn <a href='../rand/trait.Rng.html#method.gen' class='fnname'>gen</a><T>(&mut self) -> T <span class="where fmt-newline">where<br> T: <a class="trait" href="../rand/trait.Rand.html" title="trait rand::Rand">Rand</a>, </span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/rand/lib.rs.html#473-475' title='goto source code'>[src]</a></span></h4>
|
||
<h4 id='method.gen_iter-1' class="method"><div class="important-traits"><div class='tooltip'>ⓘ<span class='tooltiptext'>Important traits for <a class="struct" href="../rand/struct.Generator.html" title="struct rand::Generator">Generator</a><'a, T, R></span></div><div class="content hidden"><h3 class="important">Important traits for <a class="struct" href="../rand/struct.Generator.html" title="struct rand::Generator">Generator</a><'a, T, R></h3><code class="content"><span class="where fmt-newline">impl<'a, T, R> <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/iterator/trait.Iterator.html" title="trait core::iter::iterator::Iterator">Iterator</a> for <a class="struct" href="../rand/struct.Generator.html" title="struct rand::Generator">Generator</a><'a, T, R> <span class="where fmt-newline">where<br> R: <a class="trait" href="../rand/trait.Rng.html" title="trait rand::Rng">Rng</a>,<br> T: <a class="trait" href="../rand/trait.Rand.html" title="trait rand::Rand">Rand</a>, </span></span><span class="where fmt-newline"> type <a href='https://doc.rust-lang.org/nightly/core/iter/iterator/trait.Iterator.html#associatedtype.Item' class="type">Item</a> = T;</span></code></div></div><span id='gen_iter.v-1' class='invisible'><code>fn <a href='../rand/trait.Rng.html#method.gen_iter' class='fnname'>gen_iter</a><T>(&'a mut self) -> <a class="struct" href="../rand/struct.Generator.html" title="struct rand::Generator">Generator</a><'a, T, Self> <span class="where fmt-newline">where<br> T: <a class="trait" href="../rand/trait.Rand.html" title="trait rand::Rand">Rand</a>, </span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/rand/lib.rs.html#491-493' title='goto source code'>[src]</a></span></h4>
|
||
<h4 id='method.gen_range-1' class="method"><span id='gen_range.v-1' class='invisible'><code>fn <a href='../rand/trait.Rng.html#method.gen_range' class='fnname'>gen_range</a><T>(&mut self, low: T, high: T) -> T <span class="where fmt-newline">where<br> T: <a class="trait" href="../rand/distributions/range/trait.SampleRange.html" title="trait rand::distributions::range::SampleRange">SampleRange</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a><T>, </span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/rand/lib.rs.html#518-521' title='goto source code'>[src]</a></span></h4>
|
||
<h4 id='method.gen_weighted_bool-1' class="method"><span id='gen_weighted_bool.v-1' class='invisible'><code>fn <a href='../rand/trait.Rng.html#method.gen_weighted_bool' class='fnname'>gen_weighted_bool</a>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/rand/lib.rs.html#533-535' title='goto source code'>[src]</a></span></h4>
|
||
<h4 id='method.gen_ascii_chars-1' class="method"><div class="important-traits"><div class='tooltip'>ⓘ<span class='tooltiptext'>Important traits for <a class="struct" href="../rand/struct.AsciiGenerator.html" title="struct rand::AsciiGenerator">AsciiGenerator</a><'a, R></span></div><div class="content hidden"><h3 class="important">Important traits for <a class="struct" href="../rand/struct.AsciiGenerator.html" title="struct rand::AsciiGenerator">AsciiGenerator</a><'a, R></h3><code class="content"><span class="where fmt-newline">impl<'a, R> <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/iterator/trait.Iterator.html" title="trait core::iter::iterator::Iterator">Iterator</a> for <a class="struct" href="../rand/struct.AsciiGenerator.html" title="struct rand::AsciiGenerator">AsciiGenerator</a><'a, R> <span class="where fmt-newline">where<br> R: <a class="trait" href="../rand/trait.Rng.html" title="trait rand::Rng">Rng</a>, </span></span><span class="where fmt-newline"> type <a href='https://doc.rust-lang.org/nightly/core/iter/iterator/trait.Iterator.html#associatedtype.Item' class="type">Item</a> = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.char.html">char</a>;</span></code></div></div><span id='gen_ascii_chars.v-1' class='invisible'><code>fn <a href='../rand/trait.Rng.html#method.gen_ascii_chars' class='fnname'>gen_ascii_chars</a>(&'a mut self) -> <a class="struct" href="../rand/struct.AsciiGenerator.html" title="struct rand::AsciiGenerator">AsciiGenerator</a><'a, Self></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/rand/lib.rs.html#547-549' title='goto source code'>[src]</a></span></h4>
|
||
<h4 id='method.choose-1' class="method"><span id='choose.v-1' class='invisible'><code>fn <a href='../rand/trait.Rng.html#method.choose' class='fnname'>choose</a><T>(&mut self, values: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&'a [T]</a>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a </a>T></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/rand/lib.rs.html#565-571' title='goto source code'>[src]</a></span></h4>
|
||
<h4 id='method.choose_mut-1' class="method"><span id='choose_mut.v-1' class='invisible'><code>fn <a href='../rand/trait.Rng.html#method.choose_mut' class='fnname'>choose_mut</a><T>(&mut self, values: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&'a mut [T]</a>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>T></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/rand/lib.rs.html#576-583' title='goto source code'>[src]</a></span></h4>
|
||
<h4 id='method.shuffle-1' class="method"><span id='shuffle.v-1' class='invisible'><code>fn <a href='../rand/trait.Rng.html#method.shuffle' class='fnname'>shuffle</a><T>(&mut self, values: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&mut [T]</a>)</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/rand/lib.rs.html#602-610' title='goto source code'>[src]</a></span></h4>
|
||
</div></span><h3 id='impl-Rng-1' class='impl'><span class='in-band'><code>impl <a class="trait" href="../rand/trait.Rng.html" title="trait rand::Rng">Rng</a> for <a class="struct" href="../rand/jitter/struct.JitterRng.html" title="struct rand::jitter::JitterRng">JitterRng</a></code><a href='#impl-Rng-1' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/rand/jitter.rs.html#717-751' title='goto source code'>[src]</a></span></h3>
|
||
<span class='docblock autohide'><div class='impl-items'><h4 id='method.next_u32-1' class="method"><span id='next_u32.v-2' class='invisible'><code>fn <a href='#method.next_u32' class='fnname'>next_u32</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/rand/jitter.rs.html#718-727' title='goto source code'>[src]</a></span></h4>
|
||
<h4 id='method.next_u64-2' class="method"><span id='next_u64.v-2' class='invisible'><code>fn <a href='#method.next_u64' class='fnname'>next_u64</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u64.html">u64</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/rand/jitter.rs.html#729-731' title='goto source code'>[src]</a></span></h4>
|
||
<h4 id='method.fill_bytes-2' class="method"><span id='fill_bytes.v-2' class='invisible'><code>fn <a href='#method.fill_bytes' class='fnname'>fill_bytes</a>(&mut self, dest: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&mut [</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>)</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/rand/jitter.rs.html#733-750' title='goto source code'>[src]</a></span></h4>
|
||
<h4 id='method.next_f32-2' class="method"><span id='next_f32.v-2' class='invisible'><code>fn <a href='../rand/trait.Rng.html#method.next_f32' class='fnname'>next_f32</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.f32.html">f32</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/rand/lib.rs.html#383-389' title='goto source code'>[src]</a></span></h4>
|
||
<h4 id='method.next_f64-2' class="method"><span id='next_f64.v-2' class='invisible'><code>fn <a href='../rand/trait.Rng.html#method.next_f64' class='fnname'>next_f64</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.f64.html">f64</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/rand/lib.rs.html#401-407' title='goto source code'>[src]</a></span></h4>
|
||
<h4 id='method.gen-2' class="method"><span id='gen.v-2' class='invisible'><code>fn <a href='../rand/trait.Rng.html#method.gen' class='fnname'>gen</a><T>(&mut self) -> T <span class="where fmt-newline">where<br> T: <a class="trait" href="../rand/trait.Rand.html" title="trait rand::Rand">Rand</a>, </span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/rand/lib.rs.html#473-475' title='goto source code'>[src]</a></span></h4>
|
||
<h4 id='method.gen_iter-2' class="method"><div class="important-traits"><div class='tooltip'>ⓘ<span class='tooltiptext'>Important traits for <a class="struct" href="../rand/struct.Generator.html" title="struct rand::Generator">Generator</a><'a, T, R></span></div><div class="content hidden"><h3 class="important">Important traits for <a class="struct" href="../rand/struct.Generator.html" title="struct rand::Generator">Generator</a><'a, T, R></h3><code class="content"><span class="where fmt-newline">impl<'a, T, R> <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/iterator/trait.Iterator.html" title="trait core::iter::iterator::Iterator">Iterator</a> for <a class="struct" href="../rand/struct.Generator.html" title="struct rand::Generator">Generator</a><'a, T, R> <span class="where fmt-newline">where<br> R: <a class="trait" href="../rand/trait.Rng.html" title="trait rand::Rng">Rng</a>,<br> T: <a class="trait" href="../rand/trait.Rand.html" title="trait rand::Rand">Rand</a>, </span></span><span class="where fmt-newline"> type <a href='https://doc.rust-lang.org/nightly/core/iter/iterator/trait.Iterator.html#associatedtype.Item' class="type">Item</a> = T;</span></code></div></div><span id='gen_iter.v-2' class='invisible'><code>fn <a href='../rand/trait.Rng.html#method.gen_iter' class='fnname'>gen_iter</a><T>(&'a mut self) -> <a class="struct" href="../rand/struct.Generator.html" title="struct rand::Generator">Generator</a><'a, T, Self> <span class="where fmt-newline">where<br> T: <a class="trait" href="../rand/trait.Rand.html" title="trait rand::Rand">Rand</a>, </span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/rand/lib.rs.html#491-493' title='goto source code'>[src]</a></span></h4>
|
||
<h4 id='method.gen_range-2' class="method"><span id='gen_range.v-2' class='invisible'><code>fn <a href='../rand/trait.Rng.html#method.gen_range' class='fnname'>gen_range</a><T>(&mut self, low: T, high: T) -> T <span class="where fmt-newline">where<br> T: <a class="trait" href="../rand/distributions/range/trait.SampleRange.html" title="trait rand::distributions::range::SampleRange">SampleRange</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a><T>, </span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/rand/lib.rs.html#518-521' title='goto source code'>[src]</a></span></h4>
|
||
<h4 id='method.gen_weighted_bool-2' class="method"><span id='gen_weighted_bool.v-2' class='invisible'><code>fn <a href='../rand/trait.Rng.html#method.gen_weighted_bool' class='fnname'>gen_weighted_bool</a>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/rand/lib.rs.html#533-535' title='goto source code'>[src]</a></span></h4>
|
||
<h4 id='method.gen_ascii_chars-2' class="method"><div class="important-traits"><div class='tooltip'>ⓘ<span class='tooltiptext'>Important traits for <a class="struct" href="../rand/struct.AsciiGenerator.html" title="struct rand::AsciiGenerator">AsciiGenerator</a><'a, R></span></div><div class="content hidden"><h3 class="important">Important traits for <a class="struct" href="../rand/struct.AsciiGenerator.html" title="struct rand::AsciiGenerator">AsciiGenerator</a><'a, R></h3><code class="content"><span class="where fmt-newline">impl<'a, R> <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/iterator/trait.Iterator.html" title="trait core::iter::iterator::Iterator">Iterator</a> for <a class="struct" href="../rand/struct.AsciiGenerator.html" title="struct rand::AsciiGenerator">AsciiGenerator</a><'a, R> <span class="where fmt-newline">where<br> R: <a class="trait" href="../rand/trait.Rng.html" title="trait rand::Rng">Rng</a>, </span></span><span class="where fmt-newline"> type <a href='https://doc.rust-lang.org/nightly/core/iter/iterator/trait.Iterator.html#associatedtype.Item' class="type">Item</a> = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.char.html">char</a>;</span></code></div></div><span id='gen_ascii_chars.v-2' class='invisible'><code>fn <a href='../rand/trait.Rng.html#method.gen_ascii_chars' class='fnname'>gen_ascii_chars</a>(&'a mut self) -> <a class="struct" href="../rand/struct.AsciiGenerator.html" title="struct rand::AsciiGenerator">AsciiGenerator</a><'a, Self></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/rand/lib.rs.html#547-549' title='goto source code'>[src]</a></span></h4>
|
||
<h4 id='method.choose-2' class="method"><span id='choose.v-2' class='invisible'><code>fn <a href='../rand/trait.Rng.html#method.choose' class='fnname'>choose</a><T>(&mut self, values: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&'a [T]</a>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a </a>T></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/rand/lib.rs.html#565-571' title='goto source code'>[src]</a></span></h4>
|
||
<h4 id='method.choose_mut-2' class="method"><span id='choose_mut.v-2' class='invisible'><code>fn <a href='../rand/trait.Rng.html#method.choose_mut' class='fnname'>choose_mut</a><T>(&mut self, values: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&'a mut [T]</a>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>T></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/rand/lib.rs.html#576-583' title='goto source code'>[src]</a></span></h4>
|
||
<h4 id='method.shuffle-2' class="method"><span id='shuffle.v-2' class='invisible'><code>fn <a href='../rand/trait.Rng.html#method.shuffle' class='fnname'>shuffle</a><T>(&mut self, values: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&mut [T]</a>)</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/rand/lib.rs.html#602-610' title='goto source code'>[src]</a></span></h4>
|
||
</div></span><h3 id='impl-Rng-2' class='impl'><span class='in-band'><code>impl<R> <a class="trait" href="../rand/trait.Rng.html" title="trait rand::Rng">Rng</a> for <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a><R> <span class="where fmt-newline">where<br> R: <a class="trait" href="../rand/trait.Rng.html" title="trait rand::Rng">Rng</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></code><a href='#impl-Rng-2' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/rand/lib.rs.html#636-656' title='goto source code'>[src]</a></span></h3>
|
||
<span class='docblock autohide'><div class='impl-items'><h4 id='method.next_u32-2' class="method"><span id='next_u32.v-3' class='invisible'><code>fn <a href='#method.next_u32' class='fnname'>next_u32</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/rand/lib.rs.html#637-639' title='goto source code'>[src]</a></span></h4>
|
||
<h4 id='method.next_u64-3' class="method"><span id='next_u64.v-3' class='invisible'><code>fn <a href='#method.next_u64' class='fnname'>next_u64</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u64.html">u64</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/rand/lib.rs.html#641-643' title='goto source code'>[src]</a></span></h4>
|
||
<h4 id='method.next_f32-3' class="method"><span id='next_f32.v-3' class='invisible'><code>fn <a href='#method.next_f32' class='fnname'>next_f32</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.f32.html">f32</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/rand/lib.rs.html#645-647' title='goto source code'>[src]</a></span></h4>
|
||
<h4 id='method.next_f64-3' class="method"><span id='next_f64.v-3' class='invisible'><code>fn <a href='#method.next_f64' class='fnname'>next_f64</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.f64.html">f64</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/rand/lib.rs.html#649-651' title='goto source code'>[src]</a></span></h4>
|
||
<h4 id='method.fill_bytes-3' class="method"><span id='fill_bytes.v-3' class='invisible'><code>fn <a href='#method.fill_bytes' class='fnname'>fill_bytes</a>(&mut self, dest: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&mut [</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>)</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/rand/lib.rs.html#653-655' title='goto source code'>[src]</a></span></h4>
|
||
<h4 id='method.gen-3' class="method"><span id='gen.v-3' class='invisible'><code>fn <a href='../rand/trait.Rng.html#method.gen' class='fnname'>gen</a><T>(&mut self) -> T <span class="where fmt-newline">where<br> T: <a class="trait" href="../rand/trait.Rand.html" title="trait rand::Rand">Rand</a>, </span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/rand/lib.rs.html#473-475' title='goto source code'>[src]</a></span></h4>
|
||
<h4 id='method.gen_iter-3' class="method"><div class="important-traits"><div class='tooltip'>ⓘ<span class='tooltiptext'>Important traits for <a class="struct" href="../rand/struct.Generator.html" title="struct rand::Generator">Generator</a><'a, T, R></span></div><div class="content hidden"><h3 class="important">Important traits for <a class="struct" href="../rand/struct.Generator.html" title="struct rand::Generator">Generator</a><'a, T, R></h3><code class="content"><span class="where fmt-newline">impl<'a, T, R> <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/iterator/trait.Iterator.html" title="trait core::iter::iterator::Iterator">Iterator</a> for <a class="struct" href="../rand/struct.Generator.html" title="struct rand::Generator">Generator</a><'a, T, R> <span class="where fmt-newline">where<br> R: <a class="trait" href="../rand/trait.Rng.html" title="trait rand::Rng">Rng</a>,<br> T: <a class="trait" href="../rand/trait.Rand.html" title="trait rand::Rand">Rand</a>, </span></span><span class="where fmt-newline"> type <a href='https://doc.rust-lang.org/nightly/core/iter/iterator/trait.Iterator.html#associatedtype.Item' class="type">Item</a> = T;</span></code></div></div><span id='gen_iter.v-3' class='invisible'><code>fn <a href='../rand/trait.Rng.html#method.gen_iter' class='fnname'>gen_iter</a><T>(&'a mut self) -> <a class="struct" href="../rand/struct.Generator.html" title="struct rand::Generator">Generator</a><'a, T, Self> <span class="where fmt-newline">where<br> T: <a class="trait" href="../rand/trait.Rand.html" title="trait rand::Rand">Rand</a>, </span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/rand/lib.rs.html#491-493' title='goto source code'>[src]</a></span></h4>
|
||
<h4 id='method.gen_range-3' class="method"><span id='gen_range.v-3' class='invisible'><code>fn <a href='../rand/trait.Rng.html#method.gen_range' class='fnname'>gen_range</a><T>(&mut self, low: T, high: T) -> T <span class="where fmt-newline">where<br> T: <a class="trait" href="../rand/distributions/range/trait.SampleRange.html" title="trait rand::distributions::range::SampleRange">SampleRange</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a><T>, </span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/rand/lib.rs.html#518-521' title='goto source code'>[src]</a></span></h4>
|
||
<h4 id='method.gen_weighted_bool-3' class="method"><span id='gen_weighted_bool.v-3' class='invisible'><code>fn <a href='../rand/trait.Rng.html#method.gen_weighted_bool' class='fnname'>gen_weighted_bool</a>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/rand/lib.rs.html#533-535' title='goto source code'>[src]</a></span></h4>
|
||
<h4 id='method.gen_ascii_chars-3' class="method"><div class="important-traits"><div class='tooltip'>ⓘ<span class='tooltiptext'>Important traits for <a class="struct" href="../rand/struct.AsciiGenerator.html" title="struct rand::AsciiGenerator">AsciiGenerator</a><'a, R></span></div><div class="content hidden"><h3 class="important">Important traits for <a class="struct" href="../rand/struct.AsciiGenerator.html" title="struct rand::AsciiGenerator">AsciiGenerator</a><'a, R></h3><code class="content"><span class="where fmt-newline">impl<'a, R> <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/iterator/trait.Iterator.html" title="trait core::iter::iterator::Iterator">Iterator</a> for <a class="struct" href="../rand/struct.AsciiGenerator.html" title="struct rand::AsciiGenerator">AsciiGenerator</a><'a, R> <span class="where fmt-newline">where<br> R: <a class="trait" href="../rand/trait.Rng.html" title="trait rand::Rng">Rng</a>, </span></span><span class="where fmt-newline"> type <a href='https://doc.rust-lang.org/nightly/core/iter/iterator/trait.Iterator.html#associatedtype.Item' class="type">Item</a> = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.char.html">char</a>;</span></code></div></div><span id='gen_ascii_chars.v-3' class='invisible'><code>fn <a href='../rand/trait.Rng.html#method.gen_ascii_chars' class='fnname'>gen_ascii_chars</a>(&'a mut self) -> <a class="struct" href="../rand/struct.AsciiGenerator.html" title="struct rand::AsciiGenerator">AsciiGenerator</a><'a, Self></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/rand/lib.rs.html#547-549' title='goto source code'>[src]</a></span></h4>
|
||
<h4 id='method.choose-3' class="method"><span id='choose.v-3' class='invisible'><code>fn <a href='../rand/trait.Rng.html#method.choose' class='fnname'>choose</a><T>(&mut self, values: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&'a [T]</a>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a </a>T></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/rand/lib.rs.html#565-571' title='goto source code'>[src]</a></span></h4>
|
||
<h4 id='method.choose_mut-3' class="method"><span id='choose_mut.v-3' class='invisible'><code>fn <a href='../rand/trait.Rng.html#method.choose_mut' class='fnname'>choose_mut</a><T>(&mut self, values: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&'a mut [T]</a>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>T></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/rand/lib.rs.html#576-583' title='goto source code'>[src]</a></span></h4>
|
||
<h4 id='method.shuffle-3' class="method"><span id='shuffle.v-3' class='invisible'><code>fn <a href='../rand/trait.Rng.html#method.shuffle' class='fnname'>shuffle</a><T>(&mut self, values: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&mut [T]</a>)</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/rand/lib.rs.html#602-610' title='goto source code'>[src]</a></span></h4>
|
||
</div></span>
|
||
<h2 id='implementors' class='small-section-header'>
|
||
Implementors<a href='#implementors' class='anchor'></a>
|
||
</h2>
|
||
<ul class='item-list' id='implementors-list'>
|
||
<li><div class='out-of-band'><a class='srclink' href='../src/rand/reseeding.rs.html#61-79' title='goto source code'>[src]</a></div><code>impl<R, Rsdr> Rng for <a class="struct" href="../rand/reseeding/struct.ReseedingRng.html" title="struct rand::reseeding::ReseedingRng">ReseedingRng</a><R, Rsdr> <span class="where fmt-newline">where<br> R: <a class="trait" href="../rand/trait.Rng.html" title="trait rand::Rng">Rng</a>,<br> Rsdr: <a class="trait" href="../rand/reseeding/trait.Reseeder.html" title="trait rand::reseeding::Reseeder">Reseeder</a><R>, </span></code></li>
|
||
<li><div class='out-of-band'><a class='srclink' href='../src/rand/os.rs.html#44-48' title='goto source code'>[src]</a></div><code>impl Rng for <a class="struct" href="../rand/os/struct.OsRng.html" title="struct rand::os::OsRng">OsRng</a></code></li>
|
||
<li><div class='out-of-band'><a class='srclink' href='../src/rand/prng/isaac.rs.html#195-217' title='goto source code'>[src]</a></div><code>impl Rng for <a class="struct" href="../rand/isaac/struct.IsaacRng.html" title="struct rand::isaac::IsaacRng">IsaacRng</a></code></li>
|
||
<li><div class='out-of-band'><a class='srclink' href='../src/rand/prng/xorshift.rs.html#52-64' title='goto source code'>[src]</a></div><code>impl Rng for <a class="struct" href="../rand/struct.XorShiftRng.html" title="struct rand::XorShiftRng">XorShiftRng</a></code></li>
|
||
<li><div class='out-of-band'><a class='srclink' href='../src/rand/prng/chacha.rs.html#188-199' title='goto source code'>[src]</a></div><code>impl Rng for <a class="struct" href="../rand/chacha/struct.ChaChaRng.html" title="struct rand::chacha::ChaChaRng">ChaChaRng</a></code></li>
|
||
<li><div class='out-of-band'><a class='srclink' href='../src/rand/prng/isaac64.rs.html#196-215' title='goto source code'>[src]</a></div><code>impl Rng for <a class="struct" href="../rand/isaac/struct.Isaac64Rng.html" title="struct rand::isaac::Isaac64Rng">Isaac64Rng</a></code></li>
|
||
<li><div class='out-of-band'><a class='srclink' href='../src/rand/lib.rs.html#896-909' title='goto source code'>[src]</a></div><code>impl Rng for <a class="struct" href="../rand/struct.ThreadRng.html" title="struct rand::ThreadRng">ThreadRng</a></code></li>
|
||
<li><div class='out-of-band'><a class='srclink' href='../src/rand/lib.rs.html#803-813' title='goto source code'>[src]</a></div><code>impl Rng for <a class="struct" href="../rand/struct.StdRng.html" title="struct rand::StdRng">StdRng</a></code></li>
|
||
<li><div class='out-of-band'><a class='srclink' href='../src/rand/read.rs.html#47-66' title='goto source code'>[src]</a></div><code>impl<R> Rng for <a class="struct" href="../rand/read/struct.ReadRng.html" title="struct rand::read::ReadRng">ReadRng</a><R> <span class="where fmt-newline">where<br> R: <a class="trait" href="https://doc.rust-lang.org/nightly/std/io/trait.Read.html" title="trait std::io::Read">Read</a>, </span></code></li>
|
||
</ul><script type="text/javascript" async
|
||
src="../implementors/rand/trait.Rng.js">
|
||
</script></section>
|
||
<section id='search' class="content hidden"></section>
|
||
|
||
<section class="footer"></section>
|
||
|
||
<aside id="help" class="hidden">
|
||
<div>
|
||
<h1 class="hidden">Help</h1>
|
||
|
||
<div class="shortcuts">
|
||
<h2>Keyboard Shortcuts</h2>
|
||
|
||
<dl>
|
||
<dt><kbd>?</kbd></dt>
|
||
<dd>Show this help dialog</dd>
|
||
<dt><kbd>S</kbd></dt>
|
||
<dd>Focus the search field</dd>
|
||
<dt><kbd>↑</kbd></dt>
|
||
<dd>Move up in search results</dd>
|
||
<dt><kbd>↓</kbd></dt>
|
||
<dd>Move down in search results</dd>
|
||
<dt><kbd>↹</kbd></dt>
|
||
<dd>Switch tab</dd>
|
||
<dt><kbd>⏎</kbd></dt>
|
||
<dd>Go to active search result</dd>
|
||
<dt><kbd>+</kbd></dt>
|
||
<dd>Expand all sections</dd>
|
||
<dt><kbd>-</kbd></dt>
|
||
<dd>Collapse all sections</dd>
|
||
</dl>
|
||
</div>
|
||
|
||
<div class="infos">
|
||
<h2>Search Tricks</h2>
|
||
|
||
<p>
|
||
Prefix searches with a type followed by a colon (e.g.
|
||
<code>fn:</code>) to restrict the search to a given type.
|
||
</p>
|
||
|
||
<p>
|
||
Accepted types are: <code>fn</code>, <code>mod</code>,
|
||
<code>struct</code>, <code>enum</code>,
|
||
<code>trait</code>, <code>type</code>, <code>macro</code>,
|
||
and <code>const</code>.
|
||
</p>
|
||
|
||
<p>
|
||
Search functions by type signature (e.g.
|
||
<code>vec -> usize</code> or <code>* -> vec</code>)
|
||
</p>
|
||
</div>
|
||
</div>
|
||
</aside>
|
||
|
||
|
||
|
||
<script>
|
||
window.rootPath = "../";
|
||
window.currentCrate = "rand";
|
||
</script>
|
||
<script src="../main.js"></script>
|
||
<script defer src="../search-index.js"></script>
|
||
</body>
|
||
</html> |