- Feature Articles
- CodeSOD
-
Error'd
- Most Recent Articles
- Secret Horror
- Not Impossible
- Monkeys
- Killing Time
- Hypersensitive
- Infallabella
- Doubled Daniel
- It Figures
- 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
Edit Admin
It's not someone who's afraid of logarithms, but more afraid of mhtiragols, better known as powers (we want Math.Pow(...) rather than Math.Log(...)).
But yeah, on a scale of badness of code, this scores highly.
Admin
' *** the generates a frist post!
Admin
12345.ToString("D99") generates 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000012345
which I assume (didn't count it) is 99 digits long
Admin
I came to make the same point - glad to see I wasn't getting confused!
Edit Admin
I wonder why they cap the "number of decimals" to 99 whereas
x
will be hard-coded to1
as soon asnumDecimals > 9
(due to the conversion toint
throwing anOverflowException
).Also, the actual function... Why do they even tie the case to parity?
Admin
And... the actual function's comment gives 'aa7bb' as an example, but can't actually return that? (only 'aa7BB')
Admin
It can't return either, but can return aA7Bb
Admin
Nvm, I was mistaken
Admin
Ah, so the real WTF is they excluded z, Z and 9?
Admin
Why tie the case to parity? Generating a random character code that could be in either the capital letter range or the lowercase letter range, but not in between, is hard. It's easier to use a random number to flip the case 50% of the time. But why generate a new random number, when a perfectly good random number has already been generated? Of course they reuse
i
. To do anything else would be wasteful!Edit Admin
No, it's easy. In C/C++ style pseudocode
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"[random(0 to 51 inclusive)]
Edit Admin
Am I missing something, or is the first if block totally unnecessary? It sets
n
andx
, but these variables are never used. It fills instrNum
, but then it's immediately cleared.Could it be left over from some previous iteration of the code that used these variables?