JSFiddle - React, Tailwind, and code Playground

by konijn_gmail_com

JavaScript

/* Alea
   random = Alea.seed(123).random; Hijacked from rot.js */
Alea = {
    _frac: 2.3283064365386963e-10, /* 2^-32 */
    seed: function(seed) {
        this._s0 = ((seed||new Date().getTime()) >>> 0) * this._frac;
        this._s1 = (seed = (seed*69069 + 1) >>> 0) * this._frac;
        this._s2 = (seed = (seed*69069 + 1) >>> 0) * this._frac;
        this._c = 1;
        return this;
    },
    random: function() {
        var t = 2091639 * this._s0 + this._c * this._frac;
        this._s0 = this._s1;
        this._s1 = this._s2;
        this._c = t | 0;
        this._s2 = t - this._c;
        return this._s2;
    },
    getNormal: function(mean, stddev) {
        do {
            var u = 2*this.random()-1;
            var v = 2*this.random()-1;
            var r = u*u + v*v;
        } while (r > 1 || r == 0);

        var gauss = u * Math.sqrt(-2*Math.log(r)/r);
        return (mean || 0) + gauss*(stddev || 1);
    },
    getPercentage: function() {
        return 1 + Math.floor(this.random()*100);
    },
    pushState: function() {
        this._states = (this._states || [] ).push( JSON.stringify( this ) ); 
        return this;
    },
    popState: function(state) {
      this.merge( JSON.parse( this._states.pop() ) ); //Break on purposes
      return this;
    }
}

Alea.seed(20041977);
console.log( 0.39579378068447113 );
console.log( Alea.random() );
console.log( 0.08111128443852067 );
console.log( Alea.random() );