Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/vendor/digest/src/dev/rng.rs # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / vendor / digest / src / dev / rng.rs` 38 lines ยท 982 bytes Raw Blame History 1 //! Xorshift RNG used for tests. Based on the `rand_xorshift` crate. 2 use core::num::Wrapping; 3 4 /// Initial RNG state used in tests. 5 // chosen by fair dice roll. guaranteed to be random. 6 pub(crate) const RNG: XorShiftRng = XorShiftRng { 7 x: Wrapping(0x0787_3B4A), 8 y: Wrapping(0xFAAB_8FFE), 9 z: Wrapping(0x1745_980F), 10 w: Wrapping(0xB0AD_B4F3), 11 }; 12 13 /// Xorshift RNG instance/ 14 pub(crate) struct XorShiftRng { 15 x: Wrapping, 16 y: Wrapping, 17 z: Wrapping, 18 w: Wrapping, 19 } 20 21 impl XorShiftRng { 22 pub(crate) fn fill(&mut self, buf: &mut [u8; 1024]) { 23 for chunk in buf.chunks_exact_mut(4) { 24 chunk.copy_from_slice(&self.next_u32().to_le_bytes()); 25 } 26 } 27 28 fn next_u32(&mut self) -> u32 { 29 let x = self.x; 30 let t = x ^ (x << 11); 31 self.x = self.y; 32 self.y = self.z; 33 self.z = self.w; 34 let w = self.w; 35 self.w = w ^ (w >> 19) ^ (t ^ (t >> 8)); 36 self.w.0 37 } 38 }