1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use std::cell::RefCell;
use std::rc::Rc;
use {Source, Xorshift128Plus};
#[derive(Clone)]
pub struct Default(Rc<RefCell<Xorshift128Plus>>);
impl Default {
pub fn new() -> Default {
thread_local!(static DEFAULT: Rc<RefCell<Xorshift128Plus>> = {
Rc::new(RefCell::new(Xorshift128Plus::new([42, 69])))
});
Default(DEFAULT.with(|source| source.clone()))
}
#[inline(always)]
pub fn seed(self, seed: [u64; 2]) -> Default {
*self.0.borrow_mut() = Xorshift128Plus::new(seed);
self
}
}
impl Source for Default {
#[inline(always)]
fn read_u64(&mut self) -> u64 {
self.0.borrow_mut().read_u64()
}
}