Skip to content

Instantly share code, notes, and snippets.

View aradzie's full-sized avatar

Aliaksandr Radzivanovich aradzie

View GitHub Profile
export function XorShift128Plus(seed: number) {
const state0 = { hi: seed ^ 0xAF410049, lo: seed ^ 0x1F9D38AF };
const state1 = { hi: seed ^ 0xD19D592C, lo: seed ^ 0xBD21E214 };
const s1 = { hi: 0, lo: 0 };
const s0 = { hi: 0, lo: 0 };
const t = { hi: 0, lo: 0 };
function update() {
// s1 = state0;
s1.hi = state0.hi;
@aradzie
aradzie / MersenneTwister.ts
Last active July 3, 2020 17:44
MersenneTwister in TypeScript
// Code adapted from http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/emt19937ar.html
// Original copyright:
/*
A C-program for MT19937, with initialization improved 2002/1/26.
Coded by Takuji Nishimura and Makoto Matsumoto.
Before using, initialize the state by using init_genrand(seed)
or init_by_array(init_key, key_length).
@aradzie
aradzie / PhantomTypes.java
Created August 6, 2011 16:53
Phantom types in Java
import java.io.Reader;
import java.io.StringReader;
public class PhantomTypes {
abstract static class Data {
private Data() {}
}
static class Unvalidated extends Data {
private Unvalidated() {}