|
|
|
| Non-WTF Job: C++ Developer at Good Grievance (Ronkonkoma, NY) |
| « Prev | Page 1 | Page 2 | Next » |
|
Too...much... pain... this... early... on... Monday...
|
|
What happened to KISS?
Is he paid per line of code? I shall headdesk now. |
|
13 is not random enough. Only 13! Should have done 26 then it would be even more random... oh hold on...
|
|
The WTF is deep in this one...
|
|
What kills me is... why is this thing Unix style paths? With the tilde as shorthand for home?
|
|
But it will choose between 6 header 1's and 7 header 2's....oh never mind.
|
Thats Microsofts try at stability. |
|
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.
|
|
And he reinitializes the random number generator every time !
|
In ASP.NET the tilde represents the application root. |
|
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! |
|
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. |
|
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 :-) |
|
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. |
|
The only thing truly random in that code is the developer's thoughts at the time of witting it...
|
|
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? |
Don't be silly. 26 isn't a prime! |
|
Maybe we should get the person who wrote the subject of today's post together with the person who wrote this piece of beauty.
|
Please, for love of god, tell me you are kidding. It's of course interesting possibility to always great new object and not to use static one and in same time resolve( let's think, that you were right :) "1/6th times more often" problem with 13 case clauses, not with one if-else clause. Ohh... and by the way, it is 1/13th not 1/6. Possiblity for header.jpg is 6/13 and for header2.jpg is 7/13. |
|
See, my randomizer goes to 11.
|
Re: More Randomer
2008-06-02 09:24
•
by
NeoMojo
(unregistered)
|
No. That is an excersise for you to determine for yourself. so, if you got the perfect distribution of results for 13 attempts, i.e. 7 header2.jpgs and 6 header.jpgs, then then you would have 1/6th more header2.jpgs when compared to the number of header.jpgs. That is what I meant. |
To make it truly randomerer, he should use a random number of random numbers. |
int randomizer () { return 11; } |
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? |
|
Of course, if he was smart, he would've generated this code...
Kinda makes one wonder, what could such a generator have looked like... |
|
Seriously, everybody knows that bigger sample equals better results in statistics.~
|
int random() { return MAX + 1; } </spontaneous combustion> |
[42,42] |
|
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. |
|
I've always loved Troll-like programming!
|
|
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'?) |
|
This sure makes it easy to guess the output of the "random" generator
1. DateTime.Now.Millisecond has a value of 0 to 999 because it only returns the millesecond portion of the time. If you make a request at 12:00:00.000 and 12:00:01.000 you will have the same "random" number. 2. If two requests are made within one millisecond, they will have the same random number. CAPTCHA: Vulputate |
|
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 |
|
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)
|
What, the whole volume? I may have to take an extra-long coffee-break for this one. |
|
"This MD5 hash isn't secure enough. Do a recursive loop to MD5 it 5 times over."
|
|
Well, in fact it is true that the lower bits of most random functions contain less entropy than the higher bits.
Captcha: gravis (ftw!) |
|
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...
|
Ever heard of triple DES? |
I think you'll find much better results with (41,43) |
|
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.
|
Obviously some random numbers. |
|
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. |
It's way more random that way. |
Re: More Randomer
2008-06-02 14:37
•
by
Wonko the sane
(unregistered)
|
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... |
|
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. |
|
Loads of WTFs.
- Random method. - Not using constants. - 13 case switches for only 2 outcomes. - "can also throw exception or return 0" ???? Someone needs to teach this kid the law of large numbers. |
| « Prev | Page 1 | Page 2 | Next » |