- 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
Turns out that, in fact, ZERO is the loneliest number. Three Dog Night is full of shit.
Admin
This looks like a guid generator (ROFL)
Admin
Aparently Z is for ZERO.
Admin
I'm not so sure about the "U", though.
Admin
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. ^_^
Admin
Esto parece el trabajo de "El Zorro".*
Admin
What? What? ~~scratches head~~
Admin
<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>
Admin
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.
Admin
Did anyone else guess that there was probably a built-in function that could have avoided this mess?
Admin
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".
Admin
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.
Admin
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.
Admin
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?
Admin
Guess I should have read the rest of the replies...answer already provided. Srry bout that fellas.
Admin
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.
Admin
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'"?
Admin
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"...
Admin
I find this quite funny as well:
... which is complete rubbish. In fact it's seeding the PRNG _from_ the system time.
Admin
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.
Admin
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.
Admin
Make that 0 to 7, I think.
Admin
Actually, 10,000 is evenly divisible by 16, so he's okay there.
Admin
dubwai, you crack me up. I love it.
Admin
it should be 999, (my mistake)
Admin
Unfortunately (for me) I'm not kidding around. I have mathlexia.
Admin
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.
Admin
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.
Admin
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."
Admin
Admin
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.
Admin
Blame the Pascal language, then. That's where VB inherits this syntax from.
Admin
DZ-Jay: You need to add 1 to intRndNum, in the Mid$ function in basic the first character is 1 not 0.
Admin
Maybe he was Greek and had no concept of the number "0".
Admin
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...
Admin
Actually, it could all be replaced by
hex = Format(Length, "X")
if you don't mind having real zeroes...
Admin
So, to fix this, we add the line:
hex = iif(hex = "Z", "0", hex)
right?
Admin
Personally I'm glad to see he didn't use 16 ifs....
Admin
Oops! You are right.
-dZ.
Admin
um... um... WTF!?
I think... it would be WAY more sensible to use the value of '0'... not a Z
... peculiar
Admin
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)
Admin
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 ...
Admin
Wrong, dude. Should be:
Const C_HEXITS = "Z123456789ABCDEF"
Best,
mj
Admin
Make that Z to 7, I think
Admin
Thats gonna kill the old "10 people in the world understand binary..." joke.
1ZZZ1111Z1Z1Z1
Admin
It's not THAT easy to spot. Especially under pressure.
The answer is of course Z(new HEX notation).
Admin
Not really. It'll just be "1Z people in the world...", pronounced "Zuh-teen".
dZ.
Admin
Oh, right, sorry. The keys are right next to each other.
dZ.
Admin
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?
Admin
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.