| 1 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::cellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/::RefCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/RefCell#; |
| 2 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::rcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/::Rcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/Rc#; |
| 3 | |
| 4 | use {Sourcerust-analyzer cargo random 0.12.2 source/Source#, Xorshift128Plusrust-analyzer cargo random 0.12.2 xorshift/Xorshift128Plus#}; |
| 5 | |
| 6 | /// An instance of the default source. |
| 7 | /// |
| 8 | /// The default source is the Xorshift128+ algorithm. |
| 9 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)] |
| 10 | pub struct Defaultrust-analyzer cargo random 0.12.2 default/Default#(Rcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/Rc#<RefCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/RefCell#<Xorshift128Plusrust-analyzer cargo random 0.12.2 xorshift/Xorshift128Plus#>>); |
| 11 | |
| 12 | impl Defaultrust-analyzer cargo random 0.12.2 default/Default# { |
| 13 | /// Create an instance of the default source. |
| 14 | /// |
| 15 | /// Each thread has its own copy of the default source, and each copy is |
| 16 | /// initialized with the same default seed. Therefore, the usage is thread |
| 17 | /// safe; however, each thread is responsible for reseeding its source. |
| 18 | pub fn newrust-analyzer cargo random 0.12.2 default/impl#[Default]new().() -> Defaultrust-analyzer cargo random 0.12.2 default/Default# { |
| 19 | thread_localrust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/local/thread_local!!(static DEFAULTrust-analyzer cargo random 0.12.2 default/DEFAULT.: Rcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/Rc#<RefCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/RefCell#<Xorshift128Plusrust-analyzer cargo random 0.12.2 xorshift/Xorshift128Plus#>> = { |
| 20 | Rcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/Rc#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/impl#[`Rc<T>`]new().(RefCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/RefCell#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]new().(Xorshift128Plusrust-analyzer cargo random 0.12.2 xorshift/Xorshift128Plus#::newrust-analyzer cargo random 0.12.2 xorshift/impl#[Xorshift128Plus]new().([42, 69]))) |
| 21 | }); |
| 22 | Defaultrust-analyzer cargo random 0.12.2 default/Default#(DEFAULTrust-analyzer cargo random 0.12.2 default/DEFAULT..withrust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/local/impl#[`LocalKey<T>`]with().(|source| source.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/impl#[`Rc<T, A>`][Clone]clone().())) |
| 23 | } |
| 24 | |
| 25 | /// Seed the source. |
| 26 | /// |
| 27 | /// At least one bit of the seed should be nonzero. |
| 28 | #[inline(always)] |
| 29 | pub fn seedrust-analyzer cargo random 0.12.2 default/impl#[Default]seed().(self, seed: [u64; 2]) -> Defaultrust-analyzer cargo random 0.12.2 default/Default# { |
| 30 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefMut<'_, T>`][DerefMut]deref_mut().self.0rust-analyzer cargo random 0.12.2 default/Default#0..borrow_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow_mut().() = Xorshift128Plusrust-analyzer cargo random 0.12.2 xorshift/Xorshift128Plus#::newrust-analyzer cargo random 0.12.2 xorshift/impl#[Xorshift128Plus]new().(seed); |
| 31 | self |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | impl Sourcerust-analyzer cargo random 0.12.2 source/Source# for Defaultrust-analyzer cargo random 0.12.2 default/Default# { |
| 36 | #[inline(always)] |
| 37 | fn read_u64rust-analyzer cargo random 0.12.2 default/impl#[Default][Source]read_u64().(&mut self) -> u64 { |
| 38 | self.0rust-analyzer cargo random 0.12.2 default/Default#0..borrow_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow_mut().().read_u64rust-analyzer cargo random 0.12.2 xorshift/impl#[Xorshift128Plus][Source]read_u64().() |
| 39 | } |
| 40 | } |