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