JSFiddle - React, Tailwind, and code Playground

by blesh

JavaScript

function getHeight(minHeight, maxHeight, a) {
    var r = Math.random() * Math.sqrt(maxHeight - minHeight / a);
    return Math.pow(r, 2) + minHeight;
}

function getHeight2(minHeight, maxHeight) {
    return Math.random()*Math.random()*Math.random()*Math.random()*maxHeight + minHeight;
}

function writeDiv(i, h, color, offset) {
    div = document.createElement('div');
    div.style.position = 'absolute';
    div.style.width = '3px';
    div.style.top = '0';
    div.style.borderLeft = '1px solid ' + color;
    div.style.left = ((i * 5) + offset) + 'px';
    div.style.height = h + 'px';
    document.body.appendChild(div);
}

var i, h, div;

for(i = 0; i < 1000; i++) {
    h = getHeight2(10, 200);
    writeDiv(i, h, 'red', 0);
}

for(i = 0; i < 1000; i++) {
    h = getHeight(10, 200, .12);
    writeDiv(i, h, 'blue', 3);
}

h = 0, i = 0;
while(h < 95 && i++ < 100000) {
    h = getHeight(10, 100, .12);
}
if(i >= 100000) {
    console.log('fail');
}else{
    console.log('pass', i, h);
}