use Random;
pub struct SkipOne<R>(pub R);
impl<R: Random> Random for SkipOne<R> {
fn get_random(&mut self) -> u64 {
self.0.get_random();
self.0.get_random()
}
}
pub struct SkipTwo<R>(pub R);
impl<R: Random> Random for SkipTwo<R> {
fn get_random(&mut self) -> u64 {
self.0.get_random();
self.0.get_random();
self.0.get_random()
}
}
pub struct Concatenate32<R>(pub R);
impl<R: Random> Random for Concatenate32<R> {
fn get_random(&mut self) -> u64 {
(self.0.get_random() << 32) | (self.0.get_random() & 0xFFFFFFFF)
}
}
pub struct Xor<R>(pub R);
impl<R: Random> Random for Xor<R> {
fn get_random(&mut self) -> u64 {
self.0.get_random() ^ self.0.get_random()
}
}
pub struct Add<R>(pub R);
impl<R: Random> Random for Add<R> {
fn get_random(&mut self) -> u64 {
self.0.get_random().wrapping_add(self.0.get_random())
}
}
pub struct Multiply<R>(pub R);
impl<R: Random> Random for Multiply<R> {
fn get_random(&mut self) -> u64 {
self.0.get_random().wrapping_mul(self.0.get_random() | 1)
}
}
pub struct LastBit<R>(pub R);
impl<R: Random> Random for LastBit<R> {
fn get_random(&mut self) -> u64 {
let mut x = self.0.get_random() & 1;
for _ in 1..32 {
x <<= 1;
x |= self.0.get_random() & 1;
}
x
}
}
pub struct MultiplyByThree<R>(pub R);
impl<R: Random> Random for MultiplyByThree<R> {
fn get_random(&mut self) -> u64 {
self.0.get_random().wrapping_mul(3)
}
}
pub struct ModularDivideByThree<R>(pub R);
impl<R: Random> Random for ModularDivideByThree<R> {
fn get_random(&mut self) -> u64 {
self.0.get_random().wrapping_mul(12297829382473035776)
}
}
pub struct Hamming<R>(pub R);
impl<R: Random> Random for Hamming<R> {
fn get_random(&mut self) -> u64 {
self.0.get_random().count_ones() as u64 |
(self.0.get_random().count_ones() as u64) << 6 |
(self.0.get_random().count_ones() as u64) << 12 |
(self.0.get_random().count_ones() as u64) << 18 |
(self.0.get_random().count_ones() as u64) << 24 |
(self.0.get_random().count_ones() as u64) << 30 |
(self.0.get_random().count_ones() as u64) << 36 |
(self.0.get_random().count_ones() as u64) << 42 |
(self.0.get_random().count_ones() as u64) << 48 |
(self.0.get_random().count_ones() as u64) << 54 |
(self.0.get_random().count_ones() as u64) << 60
}
}
pub struct ParitySkip<R>(pub R);
impl<R: Random> Random for ParitySkip<R> {
fn get_random(&mut self) -> u64 {
let r = self.0.get_random();
if r & 1 == 0 {
self.0.get_random();
}
r
}
}
pub struct Rol7<R>(pub R);
impl<R: Random> Random for Rol7<R> {
fn get_random(&mut self) -> u64 {
self.0.get_random().rotate_left(7)
}
}