a somewhat random function:

``````var state = 1142311987481379417480;

function myRandom() {
var d = (new Date()).getTime();
var a = state ^ d;
state = (a + d) % 1000000000000000;
var r = Math.sin( state ) * 2309212090.32132;
return (r - Math.floor(r));
}``````

Having played around with GLSL before (which has no random function), I had some idea of how I could go about this... this is borrowed from the book of shaders:

``fract(sin(x)*1000000.0);``

this works for shaders since the shader is run on a per-pixel basis, and the pixel location is different every time this is called. The most obvious replacement for the 'x' / pixel location seemed to be time – but Allison's sketch obviously very cleverly draws multiple pixels at time, to by-pass time-dependent randomness. I did some more digging into javascript randomness, and realised that this would be impossible without some other number in the mix, that changed on every call – the 'seed' so to say. The following function provided some insight:

``````//https://hackernoon.com/how-does-javascripts-math-random-generate-random-numbers-ef0de6a20131

uint64_t state0 = 1;
uint64_t state1 = 2;
uint64_t xorshift128plus() {
uint64_t s1 = state0;
uint64_t s0 = state1;
state0 = s0;
s1 ^= s1 << 23;
s1 ^= s1 >> 17;
s1 ^= s0;
s1 ^= s0 >> 26;
state1 = s1;
return state0 + state1;
}``````

The bitwise operations (vs arithmetic) seemed useful for preventing the number getting too large or too small to essentially disappear – ie addition and multiplication risked crossing the number of bits allocated for an int, and subtraction and division would reduce it to 0, or exceed number of bits for a negative integer... hence the use of the modulo operator (which is essentially just discarding some bits when the number gets to big).

I put this into the quick-draw-omancy project (assignment 2), and well, it felt pretty much the same.