Comment On Putingz A Hex Onz Youz

One of Taka's clients needed some fairly specialized software but didn't have the budget for a complete system from scratch. After a little bit of research, Taka found some software sold by a third party that would get them 95% of the way done. Better still, the vendor had an "open source" option to that allowed them to add-on and modify the source code for an extra licensing fee. [expand full text]
« PrevPage 1 | Page 2Next »

Re: Putingz A Hex Onz Youz

2005-08-04 14:24 • by John Bigboote
Turns out that, in fact, ZERO is the loneliest number. Three Dog Night is full of shit.

Re: Putingz A Hex Onz Youz

2005-08-04 14:24 • by Daruku
This looks like a guid generator (ROFL)

Re: Putingz A Hex Onz Youz

2005-08-04 14:25 • by Grant Anderson
Aparently Z is for ZERO.

Re: Putingz A Hex Onz Youz

2005-08-04 14:25 • by John Bigboote
39892 in reply to 39890
Anonymous:
This looks like a guid generator (ROFL)




I'm not so sure about the "U", though.

Re: Putingz A Hex Onz Youz

2005-08-04 14:32 • by Doobie Dan
39893 in reply to 39892

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

Re: Putingz A Hex Onz Youz

2005-08-04 14:33 • by WTFer
Esto parece el trabajo de "El Zorro".*



* = This looks like the work of "El Zorro"

Re: Putingz A Hex Onz Youz

2005-08-04 14:34 • by Hmm
What? What? ~~scratches head~~

Re: Putingz A Hex Onz Youz

2005-08-04 14:35 • by Xepol


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

Re: Putingz A Hex Onz Youz

2005-08-04 14:37 • by Trev
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.

Re: Putingz A Hex Onz Youz

2005-08-04 14:38 • by Cthulhon
Did anyone else guess that there was probably a
built-in
function
that could have avoided this mess?

Re: Putingz A Hex Onz Youz

2005-08-04 14:51 • by Scott B.
39900 in reply to 39897
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".

Re: Putingz A Hex Onz Youz

2005-08-04 14:51 • by JohnO

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.

Re: Putingz A Hex Onz Youz

2005-08-04 14:56 • by JohnO

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.

Re: Putingz A Hex Onz Youz

2005-08-04 14:57 • by Kazrael
39905 in reply to 39893
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? 

Re: Putingz A Hex Onz Youz

2005-08-04 14:58 • by Kazrael
39906 in reply to 39905
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.

Re: Putingz A Hex Onz Youz

2005-08-04 15:03 • by Tom
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.

Re: Putingz A Hex Onz Youz

2005-08-04 15:19 • by JamesCurran
39911 in reply to 39896

Xepol:
  Z for zero, I mean SHEEZE, HAVE YOU EVER!!!


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


 

Re: Putingz A Hex Onz Youz

2005-08-04 15:21 • by Miszou

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


 

Re: Putingz A Hex Onz Youz

2005-08-04 15:23 • by Maik
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.

Re: Putingz A Hex Onz Youz

2005-08-04 15:23 • by dubwai
39914 in reply to 39907

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.

Re: Putingz A Hex Onz Youz

2005-08-04 15:29 • by Hank Miller
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.





Re: Putingz A Hex Onz Youz

2005-08-04 15:29 • by dubwai
39916 in reply to 39914
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.

Re: Putingz A Hex Onz Youz

2005-08-04 15:33 • by Somebody Else
39917 in reply to 39916
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.

Re: Putingz A Hex Onz Youz

2005-08-04 15:35 • by Ross Day
39918 in reply to 39916
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.

Re: Putingz A Hex Onz Youz

2005-08-04 15:50 • by dubwai
39921 in reply to 39917
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)

Re: Putingz A Hex Onz Youz

2005-08-04 15:51 • by dubwai
39922 in reply to 39918
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.

Re: Putingz A Hex Onz Youz

2005-08-04 15:55 • by Grimoire
39924 in reply to 39915
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.

Re: Putingz A Hex Onz Youz

2005-08-04 15:58 • by foxyshadis
39925 in reply to 39907
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.

Re: Putingz A Hex Onz Youz

2005-08-04 16:04 • by loneprogrammer
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."



Re: Putingz A Hex Onz Youz

2005-08-04 16:18 • by DZ-Jay
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.

Re: Putingz A Hex Onz Youz

2005-08-04 16:23 • by cm5400

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.

Re: Putingz A Hex Onz Youz

2005-08-04 16:57 • by Boojum
39931 in reply to 39901
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.

Re: Putingz A Hex Onz Youz

2005-08-04 17:25 • by Anonymous
39933 in reply to 39928
DZ-Jay: You need to add 1 to intRndNum, in the Mid$ function in basic the first character is 1 not 0.

Re: Putingz A Hex Onz Youz

2005-08-04 17:41 • by duck1123
Maybe he was Greek and had no concept of the number "0".

Re: Putingz A Hex Onz Youz

2005-08-04 17:47 • by A Wizard A True Star
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...

 

 

Re: Putingz A Hex Onz Youz

2005-08-04 18:36 • by Grimoire
39953 in reply to 39937
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...

Re: Putingz A Hex Onz Youz

2005-08-04 19:05 • by Gary and the Samoyeds
So, to fix this, we add the line:



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



right?



Re: Putingz A Hex Onz Youz

2005-08-04 19:25 • by phelyan
39961 in reply to 39953
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....

Re: Putingz A Hex Onz Youz

2005-08-04 19:59 • by DZ-Jay
39964 in reply to 39933
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.

Re: Putingz A Hex Onz Youz

2005-08-04 21:22 • by Ne0v001
39967 in reply to 39964
um... um... WTF!?



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



... peculiar

Re: Putingz A Hex Onz Youz

2005-08-04 23:28 • by Javelin
39970 in reply to 39911
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)


Re: Putingz A Hex Onz Youz

2005-08-04 23:47 • by vhawk

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



Re: Putingz A Hex Onz Youz

2005-08-05 03:01 • by mj
39975 in reply to 39928
DZ-Jay:
Const C_HEXITS = "0123456789ABCDEF"




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

Best,
mj

Re: Putingz A Hex Onz Youz

2005-08-05 04:03 • by Olle
39982 in reply to 39916
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

Re: Putingz A Hex Onz Youz

2005-08-05 04:10 • by JamieC
39983 in reply to 39971
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

Re: Putingz A Hex Onz Youz

2005-08-05 05:19 • by bfandreas
39991 in reply to 39970
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).

Re: Putingz A Hex Onz Youz

2005-08-05 05:29 • by DZ-Jay
39992 in reply to 39983
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.



Re: Putingz A Hex Onz Youz

2005-08-05 05:29 • by DZ-Jay
39993 in reply to 39975
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.

Re: Putingz A Hex Onz Youz

2005-08-05 05:40 • by ed
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?

Re: Putingz A Hex Onz Youz

2005-08-05 06:31 • by DZ-Jay
39997 in reply to 39995
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.



« PrevPage 1 | Page 2Next »

Add Comment