- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Too...much... pain... this... early... on... Monday...
Admin
http://xkcd.com/221/
Admin
What happened to KISS? Is he paid per line of code? I shall headdesk now.
Admin
13 is not random enough. Only 13! Should have done 26 then it would be even more random... oh hold on...
Admin
thirteenth!!!1!!11
Admin
The WTF is deep in this one...
Admin
What kills me is... why is this thing Unix style paths? With the tilde as shorthand for home?
Admin
But it will choose between 6 header 1's and 7 header 2's....oh never mind.
Admin
Admin
Creating and seeding the Random generator every time you use it? Makes me wonder why those clever API programmers bother with the Next method... it's quite obviously redundant.
Admin
And he reinitializes the random number generator every time !
Admin
Admin
Well, I'll say one thing anyway. It's possibly less predictable (especially if the rest of the code is done the same way).
Oh wait, unpredictable code... Oh yeh, maybe not so good after all!
Admin
I read the code. I read it again. My brain started to melt.
Now that I am sufficiently stupified (or stupidified if you prefer), I feel compelled to justify the code, despite the OP's explanation, which negates a need for further rumination.
The original coder had to make it so that header2.jpg showed up 1/6th times more often than header1.jpg. It was in the specification. The customer is always right.
Admin
The image path could have a different domain prefixed, e.g. they're using *nix/BSD for images, and IIS for random numbers (hey, maybe Microsoft is more random than *nix/BSD).
Imagine, they create an account sysimages on a *nix/BSD box to run images from... and maybe create other accounts for other images webimages, intranetimages, etc. and have a separate FTP access / password for each directory :-)
Admin
Admin
Well, I know a guy who tried to explain that using: (random(max_number)*random(max_number)) mod max_number is much more random usage then simply random(max_number). He didn't even care when one other guy proved mathematicly, that he was totally wrong.
Admin
The only thing truly random in that code is the developer's thoughts at the time of witting it...
Admin
The guy takes an extra step to get better random selections, then chooses the first header 6 times, and the second header 7 times; thus blowing the whole random thing.
Why did he skip case 0?
Admin
Don't be silly. 26 isn't a prime!
Admin
Maybe we should get the person who wrote the subject of today's post together with the person who wrote this piece of beauty.
Admin
Admin
See, my randomizer goes to 11.
Admin
Admin
To make it truly randomerer, he should use a random number of random numbers.
Admin
Admin
But what should the upper and lower bound be with which to choose the random number to choose a random number of random numbers of?
Admin
Of course, if he was smart, he would've generated this code...
Kinda makes one wonder, what could such a generator have looked like...
Admin
Seriously, everybody knows that bigger sample equals better results in statistics.~
Admin
int random() { return MAX + 1; }
</spontaneous combustion>
Admin
Admin
He asks for a random number from 1 through 13 but then the conditionals test 0 through 12. It only works for 13 because of the unconstrained final 'else' which doesn't even conceptually fit since he was clearly trying to itemize each possible result.
Dorkus.
Admin
I've always loved Troll-like programming!
Admin
How do we know this wasn't originally built with 13 different images that were supposed to be rotating, but gradually got replaced down to 2? (Think banner ad rotation).
Captcha: ingenium (is this the new version of 'brillant'?)
Admin
This sure makes it easy to guess the output of the "random" generator
CAPTCHA: Vulputate
Admin
Hmmm. I have a theory. The programmer originally had:
And for “some reason” it always returned header2.jpg. He then noticed that by “adding” “more randomness” to the select statement he got header.jpg more
Admin
Harking back to the time when I cared about such things: the least significant bits of a certain class of pseudo random generators are less random that the full stream (If you really want to know, read Knuth's "The Art of Computer Programming", Vol 2)
Admin
I may have to take an extra-long coffee-break for this one.
Admin
"This MD5 hash isn't secure enough. Do a recursive loop to MD5 it 5 times over."
Admin
Well, in fact it is true that the lower bits of most random functions contain less entropy than the higher bits.
Captcha: gravis (ftw!)
Admin
I'm not sure what's more depressing -- that this was my natural assumption (from years working with clients who were always right) or that someone else beat me to it...
Admin
Ever heard of triple DES?
Admin
Admin
It's awesome that the developer's goal was to be more random rather than to show each header half the time. Too bad he failed at both.
Admin
Obviously some random numbers.
Admin
As a couple people already mentioned a secondary WTF is that the random number generator gets reseeded with each call to RandomNumber(). Reseeding RNGs unnecessarily is a WTF that I see all the time - please people, stop doing that!
Seed your RNG once and only once. In .NET this means having only a single instance of the Random class - make it a static if you can't figure out a better way to do it. If you think you need to reseed your RNG very time you want a random number, you're wrong. If you think you ever need to reseed your RNG more than once, explain why (in comments if not to an actual other human being). If you can't coherently explain why, even to yourself, then you don't need to do it.
Admin
Admin
I've just tested this with dice...
OK used a table of 1-6, and 1-6 all combinations...
and the results were 1's - 2 2's - 6 3's - 5 4's - 6 5's - 2 0's - 15
Not an even mix is it...
Admin
Wonko the sane: Strange dice have you, with no spots on one side... but why would the side with no spots (which is obviously heavier) come up on top so much of the time?
Ponder this, we must.
Admin
Loads of WTFs.
Someone needs to teach this kid the law of large numbers.