Fake RNG
let anchors
let idx
let leng = 10
let size = 200
let px = 0
let py = 0
function seed() {
idx = 0
anchors = (Date.now() + '').split``
.reverse()
.map(v => parseFloat(v) / 10)
.splice(0, leng)
}
let last = 0
let zoom = 1
function rand() {
if (idx > size * size) seed()
px += zoom
py += ~~(px / size)
if (px >= size) px = 0
if (py >= size) py = 0
const point = {
x: anchors[idx % leng],
y: anchors[(idx + 1) % leng]
}
idx++
let dists = []
for (let i = 0; i < anchors.length; i += 2) {
let dx = px - anchors[i] * size
let dy = py - anchors[i + 1] * size
dists.push(Math.sqrt(dx * dx + dy * dy))
}
dists.sort()
last += (dists[0] / size - last) / 4
return last
}
seed()
let d = document
let b = d.body
with (b.appendChild(
Object.assign(d.createElement`canvas`, { width: 400, height: 400 })
).getContext`2d`) {
fillStyle = 'black'
fillRect(0, 0, 400, 400)
for (let i = 0; i < 200; i++) {
for (let j = 0; j < 200; j++) {
const c = rand() * 255
fillStyle = `rgb(${c}, ${c}, ${c})`
fillRect(j * 2, i * 2, 1, 2)
}
}
}
Another one for genuary “Create your own pseudo-random number generator and visually check the results.”