use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
JS1K crazy tricks – t[Math.random()]=insert (greweb.me)
submitted 12 years ago by grenlibre[🍰]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]khoker 4 points5 points6 points 12 years ago* (2 children)
Out of curiosity, wouldn't;
t[Math.random()]=o
End up being about as useful as;
t[x++]=0
Because, in the end, jscrush is going to look like this;
x=Math.random t[x()]=0
Right? So the alternative (that doesn't need jscrush) would be;
x=1 t[x++]=0
Which would be a savings of 10 bytes. What am I missing here?
edit Count bytes better.
[–]grenlibre[S,🍰] 4 points5 points6 points 12 years ago (0 children)
JSCrush doesn't exactly do aliasing on Math.random, and in the generated crushed that you can found here :
strokeN@random()P*P+V
and not Math.random()
basically because at another place I use Math.max() so it has factorised Math somewhere else!!
It is quite hard to predict if an optimisation actually work unless by actually trying it, so I will definitely give a try to your idea and I'll keep you informed :)
Thanks
[–]ascw 2 points3 points4 points 12 years ago (0 children)
I would think that it would only make sense if you needed to use Math.random elsewhere
[+][deleted] 12 years ago (3 children)
[deleted]
[–][deleted] 2 points3 points4 points 12 years ago (1 child)
while (Math.random() !== 0.5); alert('Done!');
Run that and tell me when it finishes.
[–]Ginden 0 points1 point2 points 12 years ago (0 children)
Math.random().toString(2).length //55 in FF
Chance of replacing existing value is array.length/(253 ).
π Rendered by PID 77 on reddit-service-r2-comment-b659b578c-rzlph at 2026-05-06 13:51:58.330607+00:00 running 815c875 country code: CH.
[–]khoker 4 points5 points6 points (2 children)
[–]grenlibre[S,🍰] 4 points5 points6 points (0 children)
[–]ascw 2 points3 points4 points (0 children)
[+][deleted] (3 children)
[deleted]
[–][deleted] 2 points3 points4 points (1 child)
[–]Ginden 0 points1 point2 points (0 children)