function genRandomText(length) { var text = ""; var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 .?-!(),\"'"; for (var i = 0; i < length; i++) text += possible.charAt(Math.floor(Math.random() * possible.length)); return text; } function genRandomInt(min, max) { // inclusive min & max return Math.floor(Math.random() * (max - min + 1)) + min; } function shiftArrayToRight(arr, places) { for (var i = 0; i < places; i++) { arr.unshift(arr.pop()); } } function textFillsScreen() { var root = document.compatMode == 'BackCompat' ? document.body : document.documentElement; return root.scrollHeight > root.clientHeight; } function fillScreenWithWhitespace() { var text = document.getElementById("text"); var charArray = [" "]; var whitespace = "               "; while(!textFillsScreen()) { text.innerHTML += whitespace; charArray.push.apply(charArray, [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "]); } for (var i = 0; i < 26; i++) { text.innerHTML += whitespace; charArray.push.apply(charArray, [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "]); } return charArray; } window.onload = function () { var textElem = document.getElementById('text'); var charArray = fillScreenWithWhitespace(); window.setInterval(function () { for (var i = 0; i < genRandomInt(1, 4); i++) { charArray[genRandomInt(0, charArray.length - 1)] = genRandomText(1); textElem.innerHTML = charArray.join(""); } shiftArrayToRight(charArray, 2); }, 25) }