JSFiddle - React, Tailwind, and code Playground
by Aeoril
HTML
<script src="http://bitwiseshiftleft.github.io/sjcl/sjcl.js"></script>
<h2>Math.random</h2>
<canvas id="canvas1"></canvas>
<h2>window.crypto</h2>
<canvas id="canvas2"></canvas>
<h2>WELL1024</h2>
<canvas id="canvas3"></canvas>
<h2>Standpoor</h2>
<canvas id="canvas4"></canvas>
CSS
html, body { padding: 0; margin: 0; width:100%;}
JavaScript
//=============== Start library code ==================
function WELL1024(seed_array){
var W = 32,
R = 32,
M1 = 3,
M2 = 24,
M3 = 10,
FACT = 2.32830643653869628906e-10,
state_i = 0,
STATE = new Array(R),
z0, z1, z2,
j;
if(seed_array && seed_array.length == 32){
for (j = 0; j < R; j++) {
STATE[j] = seed_array[j];
}
} else {
for (j = 0; j < R; j++) {
STATE[j] = Math.round(Math.random()*Math.pow(2, 32));
}
}
function MAT0POS(t,v){ return(v^(v>>t)); }
function MAT0NEG(t,v){ return(v^(v<<(-(t)))); }
function Identity(v) { return(v); }
function V0() { return STATE[state_i ]; }
function VM1() { return STATE[(state_i+M1) & 0x0000001f]; }
function VM2() { return STATE[(state_i+M2) & 0x0000001f]; }
function VM3() { return STATE[(state_i+M3) & 0x0000001f]; }
function VRm1() { return STATE[(state_i+31) & 0x0000001f]; }
function newV0(v) { STATE[(state_i+31) & 0x0000001f] = v; }
function newV1(v) { STATE[state_i] = v; }
return (function(){
z0 = VRm1();
z1 = Identity(V0()) ^ MAT0POS(8, VM1());
z2 = MAT0NEG (-19, VM2()) ^ MAT0NEG(-14,VM3());
newV1( z1 ^ z2);
newV0( MAT0NEG (-11,z0) ^ MAT0NEG(-7,z1) ^ MAT0NEG(-13,z2));
state_i = (state_i + 31) & 0x0000001f;
// ORIGINAL WAY. Seems to return range: [-0.5, 0.5]
// return (V0() * FACT);
// Bring the RNG back into the range of [0, 1] from: http://www.iro.umontreal.ca/~simardr/ssj/indexf.html
return (V0() > 0 ? V0() : V0() + 0x100000000) * FACT;
});
}
window.sprng = new...