1pub trait XorShift {
8 fn xorshift(&mut self) -> Self;
10}
11
12impl XorShift for usize {
13 fn xorshift(&mut self) -> Self {
14 (*self as u64).xorshift() as usize
15 }
16}
17
18impl XorShift for u64 {
19 fn xorshift(&mut self) -> Self {
20 *self ^= *self << 13;
21 *self ^= *self >> 7;
22 *self ^= *self << 17;
23 *self
24 }
25}
26
27impl XorShift for u32 {
28 fn xorshift(&mut self) -> Self {
29 *self ^= *self << 13;
30 *self ^= *self >> 17;
31 *self ^= *self << 5;
32 *self
33 }
34}
35
36impl XorShift for u16 {
37 fn xorshift(&mut self) -> Self {
38 (*self as u32).xorshift() as u16
39 }
40}
41
42impl XorShift for u8 {
43 fn xorshift(&mut self) -> Self {
44 *self ^= *self << 3;
45 *self ^= *self >> 7;
46 *self ^= *self << 1;
47 *self
48 }
49}