123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346 |
- <!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">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: <a class="trait" href="../rand/trait.Rand.html" title="trait rand::Rand">Rand</a>>(&mut self) -> T<br> <span class="where">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span>,
- { ... }
- <div class='item-spacer'></div> fn <a href='#method.gen_iter' class='fnname'>gen_iter</a><'a, T: <a class="trait" href="../rand/trait.Rand.html" title="trait rand::Rand">Rand</a>>(&'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> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span>,
- { ... }
- <div class='item-spacer'></div> fn <a href='#method.gen_range' class='fnname'>gen_range</a><T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a> + <a class="trait" href="../rand/distributions/range/trait.SampleRange.html" title="trait rand::distributions::range::SampleRange">SampleRange</a>>(&mut self, low: T, high: T) -> T<br> <span class="where">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></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><br> <span class="where">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span>,
- { ... }
- <div class='item-spacer'></div> fn <a href='#method.gen_ascii_chars' class='fnname'>gen_ascii_chars</a><'a>(&'a mut self) -> <a class="struct" href="../rand/struct.AsciiGenerator.html" title="struct rand::AsciiGenerator">AsciiGenerator</a><'a, Self><br> <span class="where">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span>,
- { ... }
- <div class='item-spacer'></div> fn <a href='#method.choose' class='fnname'>choose</a><'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><br> <span class="where">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span>,
- { ... }
- <div class='item-spacer'></div> fn <a href='#method.choose_mut' class='fnname'>choose_mut</a><'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><br> <span class="where">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span>,
- { ... }
- <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>)<br> <span class="where">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span>,
- { ... }
- }</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: <a class="trait" href="../rand/trait.Rand.html" title="trait rand::Rand">Rand</a>>(&mut self) -> T <span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</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: <a class="trait" href="../rand/trait.Rand.html" title="trait rand::Rand">Rand</a>, 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/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><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><'a, T: <a class="trait" href="../rand/trait.Rand.html" title="trait rand::Rand">Rand</a>>(&'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> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</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: <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a> + <a class="trait" href="../rand/distributions/range/trait.SampleRange.html" title="trait rand::distributions::range::SampleRange">SampleRange</a>>(&mut self, low: T, high: T) -> T <span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </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> <span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></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="../rand/trait.Rng.html" title="trait rand::Rng">Rng</a>> <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><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>(&'a mut self) -> <a class="struct" href="../rand/struct.AsciiGenerator.html" title="struct rand::AsciiGenerator">AsciiGenerator</a><'a, Self> <span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></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><'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> <span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></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><'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> <span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></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>) <span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></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="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>> <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>, </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: <a class="trait" href="../rand/trait.Rand.html" title="trait rand::Rand">Rand</a>>(&mut self) -> T <span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</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: <a class="trait" href="../rand/trait.Rand.html" title="trait rand::Rand">Rand</a>, 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/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><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><'a, T: <a class="trait" href="../rand/trait.Rand.html" title="trait rand::Rand">Rand</a>>(&'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> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</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: <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a> + <a class="trait" href="../rand/distributions/range/trait.SampleRange.html" title="trait rand::distributions::range::SampleRange">SampleRange</a>>(&mut self, low: T, high: T) -> T <span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </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> <span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></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="../rand/trait.Rng.html" title="trait rand::Rng">Rng</a>> <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><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>(&'a mut self) -> <a class="struct" href="../rand/struct.AsciiGenerator.html" title="struct rand::AsciiGenerator">AsciiGenerator</a><'a, Self> <span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></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><'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> <span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></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><'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> <span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></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>) <span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></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<R: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>> <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>, </span></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/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-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/lib.rs.html#637-639' 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/lib.rs.html#641-643' 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='#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-2' class="method"><span id='next_f64.v-2' 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-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/lib.rs.html#653-655' 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: <a class="trait" href="../rand/trait.Rand.html" title="trait rand::Rand">Rand</a>>(&mut self) -> T <span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</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: <a class="trait" href="../rand/trait.Rand.html" title="trait rand::Rand">Rand</a>, 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/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><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><'a, T: <a class="trait" href="../rand/trait.Rand.html" title="trait rand::Rand">Rand</a>>(&'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> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</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: <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a> + <a class="trait" href="../rand/distributions/range/trait.SampleRange.html" title="trait rand::distributions::range::SampleRange">SampleRange</a>>(&mut self, low: T, high: T) -> T <span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </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> <span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></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="../rand/trait.Rng.html" title="trait rand::Rng">Rng</a>> <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><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>(&'a mut self) -> <a class="struct" href="../rand/struct.AsciiGenerator.html" title="struct rand::AsciiGenerator">AsciiGenerator</a><'a, Self> <span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></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><'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> <span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></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><'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> <span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></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>) <span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></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/jitter.rs.html#717-751' title='goto source code'>[src]</a></div><code>impl Rng for <a class="struct" href="../rand/jitter/struct.JitterRng.html" title="struct rand::jitter::JitterRng">JitterRng</a></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/read.rs.html#47-66' title='goto source code'>[src]</a></div><code>impl<R: <a class="trait" href="https://doc.rust-lang.org/nightly/std/io/trait.Read.html" title="trait std::io::Read">Read</a>> Rng for <a class="struct" href="../rand/read/struct.ReadRng.html" title="struct rand::read::ReadRng">ReadRng</a><R></code></li>
- <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: <a class="trait" href="../rand/trait.Rng.html" title="trait rand::Rng">Rng</a>, Rsdr: <a class="trait" href="../rand/reseeding/trait.Reseeder.html" title="trait rand::reseeding::Reseeder">Reseeder</a><R>> Rng for <a class="struct" href="../rand/reseeding/struct.ReseedingRng.html" title="struct rand::reseeding::ReseedingRng">ReseedingRng</a><R, Rsdr></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/struct.ChaChaRng.html" title="struct rand::ChaChaRng">ChaChaRng</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/struct.IsaacRng.html" title="struct rand::IsaacRng">IsaacRng</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/struct.Isaac64Rng.html" title="struct rand::Isaac64Rng">Isaac64Rng</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/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/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>
- </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>
|