• (nodebb)

    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.

  • Zatapatique (unregistered)

    ' *** the generates a frist post!

  • Hans (unregistered)

    12345.ToString("D99") generates 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000012345

    which I assume (didn't count it) is 99 digits long

  • Robin (unregistered) in reply to Steve_The_Cynic

    I came to make the same point - glad to see I wasn't getting confused!

  • (nodebb)

    I wonder why they cap the "number of decimals" to 99 whereas x will be hard-coded to 1 as soon as numDecimals > 9 (due to the conversion to int throwing an OverflowException).

    Also, the actual function... Why do they even tie the case to parity?

  • NotACoder (unregistered)

    And... the actual function's comment gives 'aa7bb' as an example, but can't actually return that? (only 'aa7BB')

  • Weretaco (unregistered)

    It can't return either, but can return aA7Bb

  • Weretaco (unregistered)

    Nvm, I was mistaken

  • Tinkle (unregistered)

    Ah, so the real WTF is they excluded z, Z and 9?

  • erichamion (unregistered) in reply to Medinoc

    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!

  • (nodebb) in reply to erichamion

    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.

    No, it's easy. In C/C++ style pseudocode "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"[random(0 to 51 inclusive)]

  • (nodebb)

    Am I missing something, or is the first if block totally unnecessary? It sets n and x, but these variables are never used. It fills in strNum, but then it's immediately cleared.

    Could it be left over from some previous iteration of the code that used these variables?

Leave a comment on “The 5-Digit Session Identifier”

Log In or post as a guest

Replying to comment #:

« Return to Article