46 lines
9.7 KiB
HTML
46 lines
9.7 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="Random number generators and adapters"><title>rand::rngs - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2"href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-ca0dd0c4.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="rand" data-themes="" data-resource-suffix="" data-rustdoc-version="1.93.1 (01f6ddf75 2026-02-11) (Arch Linux rust 1:1.93.1-1)" data-channel="1.93.1" data-search-js="search-9e2438ea.js" data-stringdex-js="stringdex-a3946164.js" data-settings-js="settings-c38705f0.js" ><script src="../../static.files/storage-e2aeef58.js"></script><script defer src="../sidebar-items.js"></script><script defer src="../../static.files/main-a410ff4d.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-263c88ec.css"></noscript><link rel="icon" href="https://www.rust-lang.org/favicon.ico"></head><body class="rustdoc mod"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><rustdoc-topbar><h2><a href="#">Module rngs</a></h2></rustdoc-topbar><nav class="sidebar"><div class="sidebar-crate"><a class="logo-container" href="../../rand/index.html"><img src="https://www.rust-lang.org/logos/rust-logo-128x128-blk.png" alt="logo"></a><h2><a href="../../rand/index.html">rand</a><span class="version">0.9.2</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Module rngs</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#generators" title="Generators">Generators</a><ul><li><a href="#additional-generators" title="Additional generators">Additional generators</a></li></ul></li><li><a href="#traits-and-functionality" title="Traits and functionality">Traits and functionality</a></li></ul><h3><a href="#modules">Module Items</a></h3><ul class="block"><li><a href="#modules" title="Modules">Modules</a></li><li><a href="#structs" title="Structs">Structs</a></li></ul></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="../index.html">In crate rand</a></h2></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><section id="main-content" class="content"><div class="main-heading"><div class="rustdoc-breadcrumbs"><a href="../index.html">rand</a></div><h1>Module <span>rngs</span> <button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/rand/rngs/mod.rs.html#9-110">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Random number generators and adapters</p>
|
||
<p>This crate provides a small selection of non-<a href="https://rust-random.github.io/book/crate-reprod.html">portable</a> generators.
|
||
See also <a href="https://rust-random.github.io/book/guide-gen.html">Types of generators</a> and <a href="https://rust-random.github.io/book/guide-rngs.html">Our RNGs</a> in the book.</p>
|
||
<h3 id="generators"><a class="doc-anchor" href="#generators">§</a>Generators</h3>
|
||
<p>This crate provides a small selection of non-<a href="https://rust-random.github.io/book/crate-reprod.html">portable</a> random number generators:</p>
|
||
<ul>
|
||
<li><a href="struct.OsRng.html" title="struct rand::rngs::OsRng"><code>OsRng</code></a> is a stateless interface over the operating system’s random number
|
||
source. This is typically secure with some form of periodic re-seeding.</li>
|
||
<li><a href="struct.ThreadRng.html" title="struct rand::rngs::ThreadRng"><code>ThreadRng</code></a>, provided by <a href="../fn.rng.html" title="fn rand::rng"><code>crate::rng()</code></a>, is a handle to a
|
||
thread-local generator with periodic seeding from <a href="struct.OsRng.html" title="struct rand::rngs::OsRng"><code>OsRng</code></a>. Because this
|
||
is local, it is typically much faster than <a href="struct.OsRng.html" title="struct rand::rngs::OsRng"><code>OsRng</code></a>. It should be
|
||
secure, but see documentation on <a href="struct.ThreadRng.html" title="struct rand::rngs::ThreadRng"><code>ThreadRng</code></a>.</li>
|
||
<li><a href="struct.StdRng.html" title="struct rand::rngs::StdRng"><code>StdRng</code></a> is a CSPRNG chosen for good performance and trust of security
|
||
(based on reviews, maturity and usage). The current algorithm is ChaCha12,
|
||
which is well established and rigorously analysed.
|
||
<a href="struct.StdRng.html" title="struct rand::rngs::StdRng"><code>StdRng</code></a> is the deterministic generator used by <a href="struct.ThreadRng.html" title="struct rand::rngs::ThreadRng"><code>ThreadRng</code></a> but
|
||
without the periodic reseeding or thread-local management.</li>
|
||
<li><a href="struct.SmallRng.html" title="struct rand::rngs::SmallRng"><code>SmallRng</code></a> is a relatively simple, insecure generator designed to be
|
||
fast, use little memory, and pass various statistical tests of
|
||
randomness quality.</li>
|
||
</ul>
|
||
<p>The algorithms selected for <a href="struct.StdRng.html" title="struct rand::rngs::StdRng"><code>StdRng</code></a> and <a href="struct.SmallRng.html" title="struct rand::rngs::SmallRng"><code>SmallRng</code></a> may change in any
|
||
release and may be platform-dependent, therefore they are not
|
||
<a href="https://rust-random.github.io/book/crate-reprod.html">reproducible</a>.</p>
|
||
<h4 id="additional-generators"><a class="doc-anchor" href="#additional-generators">§</a>Additional generators</h4>
|
||
<ul>
|
||
<li>The <a href="https://crates.io/crates/rdrand"><code>rdrand</code></a> crate provides an interface to the RDRAND and RDSEED
|
||
instructions available in modern Intel and AMD CPUs.</li>
|
||
<li>The <a href="https://crates.io/crates/rand_jitter"><code>rand_jitter</code></a> crate provides a user-space implementation of
|
||
entropy harvesting from CPU timer jitter, but is very slow and has
|
||
<a href="https://github.com/rust-random/rand/issues/699">security issues</a>.</li>
|
||
<li>The <a href="https://crates.io/crates/rand_chacha"><code>rand_chacha</code></a> crate provides <a href="https://rust-random.github.io/book/crate-reprod.html">portable</a> implementations of
|
||
generators derived from the <a href="https://cr.yp.to/chacha.html">ChaCha</a> family of stream ciphers</li>
|
||
<li>The <a href="https://crates.io/crates/rand_pcg"><code>rand_pcg</code></a> crate provides <a href="https://rust-random.github.io/book/crate-reprod.html">portable</a> implementations of a subset
|
||
of the <a href="https://www.pcg-random.org/">PCG</a> family of small, insecure generators</li>
|
||
<li>The <a href="https://crates.io/crates/rand_xoshiro"><code>rand_xoshiro</code></a> crate provides <a href="https://rust-random.github.io/book/crate-reprod.html">portable</a> implementations of the
|
||
<a href="https://prng.di.unimi.it/">xoshiro</a> family of small, insecure generators</li>
|
||
</ul>
|
||
<p>For more, search <a href="https://crates.io/keywords/rng">crates with the <code>rng</code> tag</a>.</p>
|
||
<h3 id="traits-and-functionality"><a class="doc-anchor" href="#traits-and-functionality">§</a>Traits and functionality</h3>
|
||
<p>All generators implement <a href="../trait.RngCore.html" title="trait rand::RngCore"><code>RngCore</code></a> and thus also <a href="../trait.Rng.html" title="trait rand::Rng"><code>Rng</code></a>.
|
||
See also the <a href="https://rust-random.github.io/book/guide-values.html">Random Values</a> chapter in the book.</p>
|
||
<p>Secure RNGs may additionally implement the <a href="../trait.CryptoRng.html" title="trait rand::CryptoRng"><code>CryptoRng</code></a> trait.</p>
|
||
<p>Use the <a href="../../rand_core/index.html" title="mod rand_core"><code>rand_core</code></a> crate when implementing your own RNGs.</p>
|
||
</div></details><h2 id="modules" class="section-header">Modules<a href="#modules" class="anchor">§</a></h2><dl class="item-table"><dt><a class="mod" href="mock/index.html" title="mod rand::rngs::mock">mock</a><wbr><span class="stab deprecated" title="">Deprecated</span></dt><dd>Mock random number generator</dd></dl><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><dl class="item-table"><dt><a class="struct" href="struct.OsRng.html" title="struct rand::rngs::OsRng">OsRng</a></dt><dd>An interface over the operating-system’s random data source</dd><dt><a class="struct" href="struct.ReseedingRng.html" title="struct rand::rngs::ReseedingRng">Reseeding<wbr>Rng</a></dt><dd>A wrapper around any PRNG that implements <a href="../../rand_core/block/trait.BlockRngCore.html" title="trait rand_core::block::BlockRngCore"><code>BlockRngCore</code></a>, that adds the
|
||
ability to reseed it.</dd><dt><a class="struct" href="struct.SmallRng.html" title="struct rand::rngs::SmallRng">Small<wbr>Rng</a></dt><dd>A small-state, fast, non-crypto, non-portable PRNG</dd><dt><a class="struct" href="struct.StdRng.html" title="struct rand::rngs::StdRng">StdRng</a></dt><dd>A strong, fast (amortized), non-portable RNG</dd><dt><a class="struct" href="struct.ThreadRng.html" title="struct rand::rngs::ThreadRng">Thread<wbr>Rng</a></dt><dd>A reference to the thread-local generator</dd></dl></section></div></main></body></html> |