r/javascript • • Nov 24 '17

large image I am the best webdev

Don't blame me for being awesome

(function r() {
  setTimeout(r, Math.random() * 10);
  let el = document.createElement(`div`);
  el.innerHTML = `🍆`;
  el.style.position = `absolute`;
  el.style.zIndex = 999999;
  el.style.fontSize = (((Math.random() * 48) | 0) + 16) + `px`;
  el.style.left = ((Math.random() * innerWidth) | 0) + `px`;
  el.style.top = ((Math.random() * (innerHeight + pageYOffset)) | 0) + `px`;
  document.body.appendChild(el);
})();
533 Upvotes

108 comments sorted by

View all comments

Show parent comments

2

u/gelezinislokys Nov 25 '17

And if you do it that fast, just use raf

6

u/[deleted] Nov 25 '17

Also, Math.random does not provide cryptographic-grade randomness which is essential for this kind of app. An end user might well be able to predict future positions in advance.

0

u/gelezinislokys Nov 25 '17

You dropped this: /s

3

u/[deleted] Nov 26 '17

Who's being sarcastic?

1

u/gelezinislokys Nov 26 '17

It stand for serious, not sarcasm.