]> git.proxmox.com Git - rustc.git/blob - library/alloc/src/collections/btree/testing/rng.rs
New upstream version 1.52.0~beta.3+dfsg1
[rustc.git] / library / alloc / src / collections / btree / testing / rng.rs
1 /// XorShiftRng
2 pub struct DeterministicRng {
3 count: usize,
4 x: u32,
5 y: u32,
6 z: u32,
7 w: u32,
8 }
9
10 impl DeterministicRng {
11 pub fn new() -> Self {
12 DeterministicRng { count: 0, x: 0x193a6754, y: 0xa8a7d469, z: 0x97830e05, w: 0x113ba7bb }
13 }
14
15 /// Guarantees that each returned number is unique.
16 pub fn next(&mut self) -> u32 {
17 self.count += 1;
18 assert!(self.count <= 70029);
19 let x = self.x;
20 let t = x ^ (x << 11);
21 self.x = self.y;
22 self.y = self.z;
23 self.z = self.w;
24 let w_ = self.w;
25 self.w = w_ ^ (w_ >> 19) ^ (t ^ (t >> 8));
26 self.w
27 }
28 }