Skip to content

Instantly share code, notes, and snippets.

@weihanglo
Last active January 5, 2025 13:57
Show Gist options
  • Select an option

  • Save weihanglo/4d0c9879ccf49f64c79c1835326eb1d5 to your computer and use it in GitHub Desktop.

Select an option

Save weihanglo/4d0c9879ccf49f64c79c1835326eb1d5 to your computer and use it in GitHub Desktop.

Revisions

  1. weihanglo revised this gist Jan 5, 2025. 1 changed file with 5 additions and 7 deletions.
    12 changes: 5 additions & 7 deletions xor_shift64.rs
    Original file line number Diff line number Diff line change
    @@ -1,20 +1,18 @@
    pub struct XorShift64 {
    a: u64,
    }
    pub struct XorShift64(u64);

    impl XorShift64 {
    pub fn next(&mut self) -> u64 {
    let mut x = self.a;
    pub const fn next(&mut self) -> u64 {
    let mut x = self.0;
    x ^= x << 13;
    x ^= x >> 7;
    x ^= x << 17;
    self.a = x;
    self.0 = x;
    x
    }
    }

    fn main() {
    let mut rng = XorShift64 { a: 123456789 };
    let mut rng = XorShift64(123456789);
    for _ in 0..10 {
    println!("{}", rng.next());
    }
  2. weihanglo revised this gist Aug 26, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion xor_shift64.rs
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@ impl XorShift64 {
    x ^= x >> 7;
    x ^= x << 17;
    self.a = x;
    x
    x
    }
    }

  3. weihanglo revised this gist Aug 26, 2020. 1 changed file with 7 additions and 6 deletions.
    13 changes: 7 additions & 6 deletions xor_shift64.rs
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,16 @@
    pub struct XorShift64 {
    a: u64,
    }

    impl XorShift64 {
    pub fn next(&mut self) -> u64 {
    let mut x = self.a;
    x ^= x << 13;
    x ^= x >> 7;
    x ^= x << 17;
    self.a = x;
    let mut x = self.a;
    x ^= x << 13;
    x ^= x >> 7;
    x ^= x << 17;
    self.a = x;
    x
    }
    }
    }

    fn main() {
  4. weihanglo revised this gist Aug 26, 2020. No changes.
  5. weihanglo created this gist Sep 8, 2019.
    20 changes: 20 additions & 0 deletions xor_shift64.rs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    pub struct XorShift64 {
    a: u64,
    }
    impl XorShift64 {
    pub fn next(&mut self) -> u64 {
    let mut x = self.a;
    x ^= x << 13;
    x ^= x >> 7;
    x ^= x << 17;
    self.a = x;
    x
    }
    }

    fn main() {
    let mut rng = XorShift64 { a: 123456789 };
    for _ in 0..10 {
    println!("{}", rng.next());
    }
    }