#!/usr/bin/ruby

# https://rosettacode.org/wiki/Pseudo-random_numbers/Xorshift_star

class Xorshift_star(state) {

    define (
        mask32 = (2**32 - 1),
        mask64 = (2**64 - 1),
    )

    method next_int {
        state ^= (state >> 12)
        state ^= (state << 25 & mask64)
        state ^= (state >> 27)
        ((state * 0x2545F4914F6CDD1D) >> 32) & mask32
    }

    method next_float {
        self.next_int / (mask32+1) -> float
    }
}

say 'Seed: 1234567, first 5 values:';
var rng = Xorshift_star(1234567)
var arr = 5.of { rng.next_int }
assert_eq(arr, [3540625527, 2750739987, 4037983143, 1993361440, 3809424708])
say arr
