• John Bigboote (cs)

    Turns out that, in fact, ZERO is the loneliest number. Three Dog Night is full of shit.

  • Daruku (unregistered)

    This looks like a guid generator (ROFL)

  • Grant Anderson (unregistered)

    Aparently Z is for ZERO.

  • John Bigboote (cs) in reply to Daruku
    Anonymous:
    This looks like a guid generator (ROFL)


    I'm not so sure about the "U", though.
  • Doobie Dan (cs) in reply to John Bigboote

    Has nobody else noticed that Length is re-used inside the loop?  It doesn't matter what you pass into this, your ID will always be a random length less than 16.  Unless that was an Alex transcription error...

    And yes, Z is for zero.  ^_^

  • WTFer (cs)

    Esto parece el trabajo de "El Zorro".*

    • = This looks like the work of "El Zorro"
  • Hmm (unregistered)

    What? What? ~~scratches head~~

  • Xepol (cs)

    <ack><gurgle>

    MEDIC!!!!! We've got another one down from bad code poisoning!!!

    Ya know, code like that should come with a warning first, hidden like a spoiler. Reading that has scared my for life.

    Z for zero, I mean SHEEZE, HAVE YOU EVER!!! <walks away ranting, waving hands in air>

  • Trev (unregistered)

    So Length is passed in, and the for loop is keyed on it, but inside the for loop Length changes.  Maybe I'm not intimitely familiar with VB's scoping rules, but doesn't that have the effect of producing up to, but not necessarily, 15 characters?  Odd, and not even close to GUID.

  • Cthulhon (cs)

    Did anyone else guess that there was probably a built-in function that could have avoided this mess?

  • Scott B. (cs) in reply to Trev

    It's not so much scoping, as it is that VB only checks the value once, or stores it somewhere else or something.

        Dim i, length, c As Integer
        length = 20
        c = 0
        For i = 1 To length
            length = 1
            c = c + 1
        Next
        Text1.Text = c & " " & length

    will display "20 1".

  • JohnO (cs)

    I found this one intriguing because I wasn't sure if:

    1) the last line would result in a recursive function call or not -- it doesn't.  I've always hated the non-intuitive method of returning function values in VB

    2) changing Length inside the for loop would effect how many times it executed -- it doesn't.

    So reusing Length and Z are the only WTFs that I can find.

  • JohnO (cs)

    The real question for today is, what almost universally-recognized bad programming practice will someone defend today?  Will it be...

    Not using option explicit to force variable typing and declaration, or,

    Reusing a function parameter that is passed by reference as a local (I can't wait to hear the explanations for why this is smart in real-time programming situations).

    I just realized that I missed the Rnd * 1000 instead of rnd * 16 WTF.

  • Kazrael (cs) in reply to Doobie Dan
    Doobie Dan:

    Has nobody else noticed that Length is re-used inside the loop?  It doesn't matter what you pass into this, your ID will always be a random length less than 16.  Unless that was an Alex transcription error...

    And yes, Z is for zero.  ^_^



    The max you could get out of this function is a length of 15 (due to the fact that value mod 16 returns 0 to 15, and the length runs 1 through length).

    Unless of course I'm incorrect and the loop terminator is actually cached and does not use the local variable.  Anyone care to note if it is cached or truly uses the local variable? 
  • Kazrael (cs) in reply to Kazrael
    Kazrael:
    Doobie Dan:

    Has nobody else noticed that Length is re-used inside the loop?  It doesn't matter what you pass into this, your ID will always be a random length less than 16.  Unless that was an Alex transcription error...

    And yes, Z is for zero.  ^_^



    The max you could get out of this function is a length of 15 (due to the fact that value mod 16 returns 0 to 15, and the length runs 1 through length).

    Unless of course I'm incorrect and the loop terminator is actually cached and does not use the local variable.  Anyone care to note if it is cached or truly uses the local variable? 


    Guess I should have read the rest of the replies...answer already provided.  Srry bout that fellas.
  • Tom (unregistered)

    I dunno. I ran 300,000 iterations of that function on four or five different length values, and I never got a wrong length. The only crappy thing I can see is the "Z". But this procedure certainly works, even if it is eye-wateringly ugly.

  • JamesCurran (cs) in reply to Xepol

    Xepol:
    <ACK><GURGLE>  Z for zero, I mean SHEEZE, HAVE YOU EVER!!! <WALKS air in hands waving ranting, away>

    The time when I write an intentional WTF (for fun), I always include the line:

           Z = 1 * 2 * 3 * 4  * 5 * 6 * 7 * 8 * 9 * 0;

    People, when trying to cipher the code (pun intented), always consider discovering the Z = 0 a major accomplishment.   I'm like, "Well, why did you think I called it 'Z'"?

     

  • Miszou (cs)

    Since the (alleged) GUID is stored as a varchar, it could probably benefiit from some Hungarian notation too, just to clarify it's type.

    For example, "sGUID" could mean "string GUID".

    Or it could mean "sometimes GUID"...

     

  • Maik (unregistered)

    I find this quite funny as well:

    Alex Papadimoulis:
      'Randomize the system timer
      Randomize Timer()
    


    ... which is complete rubbish. In fact it's seeding the PRNG _from_ the system time.
  • dubwai (cs) in reply to Tom

    Anonymous:
    I dunno. I ran 300,000 iterations of that function on four or five different length values, and I never got a wrong length. The only crappy thing I can see is the "Z". But this procedure certainly works, even if it is eye-wateringly ugly.

    I guess that's one of the features of For-To right?

    The thing I noticed is that since it's getting a random number from 0 to 9999, it's defeating the randomness of the number to a small degree.  0 to 9 are slightly more likely than A to F if my calculations are correct.

  • Hank Miller (unregistered)

    The code is bad enough, but the function name generateHex is an odd name for a GUID generator, even if the output is in hex.


  • dubwai (cs) in reply to dubwai
    dubwai:

    Anonymous:
    I dunno. I ran 300,000 iterations of that function on four or five different length values, and I never got a wrong length. The only crappy thing I can see is the "Z". But this procedure certainly works, even if it is eye-wateringly ugly.

    I guess that's one of the features of For-To right?

    The thing I noticed is that since it's getting a random number from 0 to 9999, it's defeating the randomness of the number to a small degree.  0 to 9 are slightly more likely than A to F if my calculations are correct.

    Make that 0 to 7, I think.

  • Somebody Else (unregistered) in reply to dubwai
    dubwai:
    dubwai:

    Anonymous:
    I dunno. I ran 300,000 iterations of that function on four or five different length values, and I never got a wrong length. The only crappy thing I can see is the "Z". But this procedure certainly works, even if it is eye-wateringly ugly.

    I guess that's one of the features of For-To right?

    The thing I noticed is that since it's getting a random number from 0 to 9999, it's defeating the randomness of the number to a small degree.  0 to 9 are slightly more likely than A to F if my calculations are correct.

    Make that 0 to 7, I think.

    Actually, 10,000 is evenly divisible by 16, so he's okay there.

  • Ross Day (cs) in reply to dubwai
    dubwai:
    dubwai:

    The thing I noticed is that since it's getting a random number from 0 to 9999, it's defeating the randomness of the number to a small degree.  0 to 9 are slightly more likely than A to F if my calculations are correct.

    Make that 0 to 7, I think.



    dubwai, you crack me up.  I love it.
  • dubwai (cs) in reply to Somebody Else
    Anonymous:
    dubwai:
    dubwai:

    Anonymous:
    I dunno. I ran 300,000 iterations of that function on four or five different length values, and I never got a wrong length. The only crappy thing I can see is the "Z". But this procedure certainly works, even if it is eye-wateringly ugly.

    I guess that's one of the features of For-To right?

    The thing I noticed is that since it's getting a random number from 0 to 9999, it's defeating the randomness of the number to a small degree.  0 to 9 are slightly more likely than A to F if my calculations are correct.

    Make that 0 to 7, I think.

    Actually, 10,000 is evenly divisible by 16, so he's okay there.

    it should be 999, (my mistake)

  • dubwai (cs) in reply to Ross Day
    Ross Day:
    dubwai:
    dubwai:

    The thing I noticed is that since it's getting a random number from 0 to 9999, it's defeating the randomness of the number to a small degree.  0 to 9 are slightly more likely than A to F if my calculations are correct.

    Make that 0 to 7, I think.



    dubwai, you crack me up.  I love it.

    Unfortunately (for me) I'm not kidding around.  I have mathlexia.

  • Grimoire (cs) in reply to Hank Miller
    Anonymous:
    The code is bad enough, but the function name generateHex is an odd name for a GUID generator, even if the output is in hex.

    Considering that it isn't a GUID generator, I guess it's ok to call it generateHex.  Maybe generateHexString would be better...

    RFC 4122 anyone?

    I really like his aversion to 0 though.  I guess he didn't want people to get confused with O.

  • foxyshadis (cs) in reply to Tom

    Interesting, I never thought I'd need to use Replace(GenerateHex(32),"Z","0") to get a semi-valid guid. (You still have to add dashes properly, or translate it to binary.) But then I'd never want to use it either.

    Of course it's not a guid generator, just a random hex string generator that can be used as one.

  • loneprogrammer (cs)

    This reminds me of a Dilbert.

    Accounting troll, to Dilbert:  "This is our random number generator."

    Another troll:  "9, 9, 9, 9, 9..."

    Dilbert:  "Are you sure that's random?"

    Troll:  "That's the problem with randomness.  You can never be sure."

  • DZ-Jay (cs)

    Const C_HEXITS = "0123456789ABCDEF"

    Function
    GenerateHexString(Length)
    Dim i, intRndNum, strHex

    Randomize()
    For i = 1 To Length
    intRndNum = CInt(Rnd() * 16)
    strHex = strHex & Mid(C_HEXITS, intRndNum, 1)
    Next

    GenerateHexString = strHex
    End Function


    Ta-daaaa...! Old Skool.

    -dZ.

  • cm5400 (cs)

    I wonder if Ralph the porcelin bus driver is available...  Please somebody give this developer a crack in the head.  Most people know that Hexidecimal system does not have Z's in it!  By the way, I forgot to login and I noticed that I had a CAPTCHA and the word was "POSTAL"!  HAHAHAHAHAHA  Fits perfectly.

  • Boojum (unregistered) in reply to JohnO
    JohnO:
    1) the last line would result in a recursive function call or not -- it doesn't.  I've always hated the non-intuitive method of returning function values in VB


    Blame the Pascal language, then.  That's where VB inherits this syntax from.
  • Anonymous (unregistered) in reply to DZ-Jay

    DZ-Jay: You need to add 1 to intRndNum, in the Mid$ function in basic the first character is 1 not 0.

  • duck1123 (cs)

    Maybe he was Greek and had no concept of the number "0".

  • A Wizard A True Star (cs)
    Alex Papadimoulis:


        'Convert Int to Hex
        Select Case Length
          Case 1
            hex = "1"
          Case 2
            hex = "2"
          Case 3
            hex = "3"
          Case 4
            hex = "4"
          Case 5
            hex = "5"
          Case 6
            hex = "6"
          Case 7
            hex = "7"
          Case 8
            hex = "8"
          Case 9
            hex = "9"
          Case 10
            hex = "A"
          Case 11
            hex = "B"
          Case 12
            hex = "C"
          Case 13
            hex = "D"
          Case 14
            hex = "E"
          Case 15
            hex = "F"
          Case Else
            hex = "Z"
        End Select

    Strange that no one's pointed out the stupidity of cases 1 through 9 yet, when he could simply say:

    Case Is <= 9

       hex = CStr(Length)

    Guess it's too obvious...

     

     

  • Grimoire (cs) in reply to A Wizard A True Star
    A Wizard A True Star:

    Strange that no one's pointed out the stupidity of cases 1 through 9 yet, when he could simply say:

    Case Is <= 9

       hex = CStr(Length)

    Guess it's too obvious...



    Actually, it could all be replaced by

    hex = Format(Length, "X")

    if you don't mind having real zeroes...
  • Gary and the Samoyeds (unregistered)

    So, to fix this, we add the line:

    hex = iif(hex = "Z", "0", hex)

    right?

  • phelyan (cs) in reply to Grimoire
    Grimoire:
    A Wizard A True Star:

    Strange that no one's pointed out the stupidity of cases 1 through 9 yet, when he could simply say:

    Case Is <= 9

       hex = CStr(Length)

    Guess it's too obvious...



    Actually, it could all be replaced by

    hex = Format(Length, "X")

    if you don't mind having real zeroes...


    Personally I'm glad to see he didn't use 16 ifs....
  • DZ-Jay (cs) in reply to Anonymous
    Anonymous:
    DZ-Jay: You need to add 1 to intRndNum, in the Mid$ function in basic the first character is 1 not 0.


    Oops! You are right.

        -dZ.
  • Ne0v001 (unregistered) in reply to DZ-Jay

    um... um... WTF!?

    I think... it would be WAY more sensible to use the value of '0'... not a Z

    ... peculiar

  • Javelin (unregistered) in reply to JamesCurran
    JamesCurran:

    The time when I write an intentional WTF (for fun), I always include the line:

           Z = 1 * 2 * 3 * 4  * 5 * 6 * 7 * 8 * 9 * 0;


    My favorite Extra Credit question from a midterm in a CS Theory course (after we'd covered the Fast Fourier Transform) was:

    Extra Credit (1 pt):

    Give the fully simplified form of the polynomial (x - a) (x - b) ... (x - z)

  • vhawk (unregistered)

    Breaking news ...  we have just learned that the hexadecimal number system has lost it's '0's due to an hostile takeover bid.  A foreign invasion of  'Z's  - referring to the programmers having  'Zero' brains has however  agreed to  temporary fill the terrible gap left by the unexplained demise of the number '0'.  Stay tuned as we will keep you up to date should any other numbers in this numbering system follow '0''s lead and leave the number system ...

  • mj (unregistered) in reply to DZ-Jay
    DZ-Jay:
    Const C_HEXITS = "0123456789ABCDEF"


    Wrong, dude. Should be:
    Const C_HEXITS = "Z123456789ABCDEF"

    Best,
    mj
  • Olle (unregistered) in reply to dubwai
    dubwai:
    dubwai:

    Anonymous:
    I dunno. I ran 300,000 iterations of that function on four or five different length values, and I never got a wrong length. The only crappy thing I can see is the "Z". But this procedure certainly works, even if it is eye-wateringly ugly.

    I guess that's one of the features of For-To right?

    The thing I noticed is that since it's getting a random number from 0 to 9999, it's defeating the randomness of the number to a small degree.  0 to 9 are slightly more likely than A to F if my calculations are correct.

    Make that 0 to 7, I think.



    Make that Z to 7, I think
  • JamieC (unregistered) in reply to vhawk
    Anonymous:

    Breaking news ...  we have just learned that the hexadecimal number system has lost it's '0's due to an hostile takeover bid.  A foreign invasion of  'Z's  - referring to the programmers having  'Zero' brains has however  agreed to  temporary fill the terrible gap left by the unexplained demise of the number '0'.  Stay tuned as we will keep you up to date should any other numbers in this numbering system follow '0''s lead and leave the number system ...

     

    Thats gonna kill the old "10 people in the world understand binary..." joke.

    1ZZZ1111Z1Z1Z1

  • bfandreas (unregistered) in reply to Javelin
    JamesCurran:

    Give the fully simplified form of the polynomial (x - a) (x - b) ... (x - z)



    It's not THAT easy to spot. Especially under pressure.

    The answer is of course Z(new HEX notation).
  • DZ-Jay (cs) in reply to JamieC
    Anonymous:
    Anonymous:

    Breaking news ...  we have just learned that the hexadecimal number system has lost it's '0's due to an hostile takeover bid.  A foreign invasion of  'Z's  - referring to the programmers having  'Zero' brains has however  agreed to  temporary fill the terrible gap left by the unexplained demise of the number '0'.  Stay tuned as we will keep you up to date should any other numbers in this numbering system follow '0''s lead and leave the number system ...

     

    Thats gonna kill the old "10 people in the world understand binary..." joke.

    1ZZZ1111Z1Z1Z1



    Not really.  It'll just be "1Z people in the world...", pronounced "Zuh-teen".

        dZ.

  • DZ-Jay (cs) in reply to mj
    Anonymous:
    DZ-Jay:
    Const C_HEXITS = "0123456789ABCDEF"


    Wrong, dude. Should be:
    Const C_HEXITS = "Z123456789ABCDEF"

    Best,
    mj


    Oh, right, sorry.  The keys are right next to each other.

        dZ.
  • ed (unregistered)
    Alex Papadimoulis:
        Length = CInt(Rnd * 1000) Mod 16


    What exactly does the line above? I'm not familiar with VB at all but common sense points that it gets a random number, multiplies it with 1000 and than computes the modulus with 16. If this is correct than Length will always be either 0 or 8, right?
  • DZ-Jay (cs) in reply to ed
    Anonymous:
    Alex Papadimoulis:
        Length = CInt(Rnd * 1000) Mod 16


    What exactly does the line above? I'm not familiar with VB at all but common sense points that it gets a random number, multiplies it with 1000 and than computes the modulus with 16. If this is correct than Length will always be either 0 or 8, right?


    The "programmer" assumes (quite correctly) that Rnd() will yield a fractional number -- I believe that the random numbers are within the interval [0, 1) -- and so multiplies by 1000 to get some large whole number.  Then the modulus 16 will be (what he would expect to be) the seeked for random number between 0 and 15.  It would have been easier, and more intuitive, to use the text-book formula for random number generation:
       ( (upperlimit - lowerlimit + 1) * Rnd()) + lowerlimit )

    Being that upperlimit = 15 and lowerlimit = 0, then this is the same as saying:

        ( 16 * Rnd() )
    But obviously, this "programmer" has shown a lack of inclination towards the easy or intuitive -- not to mention an aversion to basic research.

        dZ.

Leave a comment on “Putingz A Hex Onz Youz”

Log In or post as a guest

Replying to comment #:

« Return to Article