• (cs)

    Too...much... pain... this... early... on... Monday...

  • tag (unregistered)

    http://xkcd.com/221/

  • St. Doodle (unregistered)

    What happened to KISS? Is he paid per line of code? I shall headdesk now.

  • Eric (unregistered)

    13 is not random enough. Only 13! Should have done 26 then it would be even more random... oh hold on...

  • (cs)

    thirteenth!!!1!!11

  • floorpie (unregistered)

    The WTF is deep in this one...

  • Alex G. (unregistered)

    What kills me is... why is this thing Unix style paths? With the tilde as shorthand for home?

  • [ICR] (unregistered)

    But it will choose between 6 header 1's and 7 header 2's....oh never mind.

  • (cs) in reply to Alex G.
    Alex G.:
    What kills me is... why is this thing Unix style paths? With the tilde as shorthand for home?
    Thats Microsofts try at stability.
  • coward (unregistered)

    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.

  • alex (unregistered)

    And he reinitializes the random number generator every time !

  • Adam (unregistered)
    What kills me is... why is this thing Unix style paths? With the tilde as shorthand for home?
    In ASP.NET the tilde represents the application root.
  • Stooshie (unregistered)

    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!

  • NeoMojo (unregistered)

    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.

  • fruey (unregistered) in reply to Alex G.

    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 :-)

  • (cs)
  • Proko (unregistered)

    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.

  • bene (unregistered)

    The only thing truly random in that code is the developer's thoughts at the time of witting it...

  • Crash Magnet (unregistered)

    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?

  • ARG (unregistered) in reply to Eric
    13 is not random enough. Only 13! Should have done 26 then it would be even more random... oh hold on...

    Don't be silly. 26 isn't a prime!

  • (cs)

    Maybe we should get the person who wrote the subject of today's post together with the person who wrote this piece of beauty.

  • Proko (unregistered) in reply to NeoMojo
    NeoMojo:
    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.
    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.
  • jtl (unregistered)

    See, my randomizer goes to 11.

  • NeoMojo (unregistered) in reply to Proko
    Proko:
    Please, for love of god, tell me you are kidding.
    No. That is an excersise for you to determine for yourself.
    Proko:
    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.
    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.
  • Biggle (unregistered) in reply to Eric
    Eric:
    13 is not random enough. Only 13! Should have done 26 then it would be even more random... oh hold on...

    To make it truly randomerer, he should use a random number of random numbers.

  • Anon. (unregistered) in reply to jtl
    jtl:
    See, my randomizer goes to 11.
    int randomizer () { return 11; }
  • (cs) in reply to Biggle
    Biggle:
    Eric:
    13 is not random enough. Only 13! Should have done 26 then it would be even more random... oh hold on...

    To make it truly randomerer, he should use a random number of random numbers.

    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?

  • CP (unregistered)

    Of course, if he was smart, he would've generated this code...

    Kinda makes one wonder, what could such a generator have looked like...

  • yetihehe (unregistered)

    Seriously, everybody knows that bigger sample equals better results in statistics.~

  • (cs) in reply to Anon.
    Anon.:
    jtl:
    See, my randomizer goes to 11.
    int randomizer () { return 11; }

    int random() { return MAX + 1; }

    </spontaneous combustion>

  • (cs) in reply to ChZEROHag
    ChZEROHag:
    Biggle:
    Eric:
    13 is not random enough. Only 13! Should have done 26 then it would be even more random... oh hold on...

    To make it truly randomerer, he should use a random number of random numbers.

    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?

    [42,42]

  • DL (unregistered)

    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.

  • CrazyFrog (unregistered)

    I've always loved Troll-like programming!

  • Cowbert (unregistered)

    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'?)

  • randoom (unregistered)

    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

  • More (unregistered)

    Hmmm. I have a theory. The programmer originally had:

    Dim rNumber As Integer = 0
    rNumber = RandomNumber(1, 2)
    Select Case rNumber
    Case 0
    Me.hl_logo.ImageUrl = "~/sysimages/header.jpg"
    Case 1
    Me.hl_logo.ImageUrl = "~/sysimages/header2.jpg"
    Case Else
    Me.hl_logo.ImageUrl = "~/sysimages/header2.jpg"
    End Select

    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

  • Andreas (unregistered)

    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)

  • (cs) in reply to Andreas
    Andreas:
    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.

  • JustChris (unregistered)

    "This MD5 hash isn't secure enough. Do a recursive loop to MD5 it 5 times over."

  • kluizenaar (unregistered)

    Well, in fact it is true that the lower bits of most random functions contain less entropy than the higher bits.

    Captcha: gravis (ftw!)

  • Beo (unregistered) in reply to Cowbert

    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...

  • (cs) in reply to JustChris
    JustChris:
    "This MD5 hash isn't secure enough. Do a recursive loop to MD5 it 5 times over."

    Ever heard of triple DES?

  • Ken B (unregistered) in reply to snoofle
    snoofle:
    ChZEROHag:
    Biggle:
    Eric:
    13 is not random enough. Only 13! Should have done 26 then it would be even more random... oh hold on...
    To make it truly randomerer, he should use a random number of random numbers.
    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?
    [42,42]
    I think you'll find much better results with
    (41,43)
  • Monkey Brains (unregistered)

    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.

  • kris (unregistered) in reply to ChZEROHag
    ChZEROHag:
    Biggle:
    Eric:
    13 is not random enough. Only 13! Should have done 26 then it would be even more random... oh hold on...

    To make it truly randomerer, he should use a random number of random numbers.

    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?

    Obviously some random numbers.

  • Manic Mailman (unregistered)

    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.

  • (cs) in reply to alex
    alex:
    And he reinitializes the random number generator every time !
    It's way more random that way.
  • Wonko the sane (unregistered) in reply to Proko
    Proko:
    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.

    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...

  • (cs)

    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.

  • Si. (unregistered)

    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.

Leave a comment on “More Randomer”

Log In or post as a guest

Replying to comment #198332:

« Return to Article